Skip to content

Commit 9984762

Browse files
committed
cyrllic support init
1 parent b772705 commit 9984762

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

patches/bnf+1.0.1.patch

+68-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
diff --git a/node_modules/bnf/BnfRules.js b/node_modules/bnf/BnfRules.js
2-
index 1f949c1..aa002da 100755
2+
index 1f949c1..098e140 100755
33
--- a/node_modules/bnf/BnfRules.js
44
+++ b/node_modules/bnf/BnfRules.js
5-
@@ -135,9 +135,13 @@ exports.bnfRules = {
5+
@@ -19,6 +19,9 @@ exports.bnfRules = {
6+
7+
return false;
8+
},
9+
+ REALPHA(token){
10+
+ return token.TryRe(/^\p{L}/u);
11+
+ },
12+
SYMBOL( token ){
13+
if( token.CharIs( 33 )
14+
|| token.CharCodeRange( 35, 38 )
15+
@@ -35,7 +38,7 @@ exports.bnfRules = {
16+
},
17+
ANYCHAR( token ){
18+
return token.Or( [
19+
- token.Rule( "ALPHA" ),
20+
+ token.Rule( "REALPHA" ),
21+
token.Rule( "DIGIT" ),
22+
token.Rule( "SYMBOL" ),
23+
token.Rule( "ONEWSP" )
24+
@@ -135,9 +138,13 @@ exports.bnfRules = {
625
ESCAQUOTE( token ){
726
return token.TryString( Buffer.from( [ 92, 96 ] ) );
827
},
@@ -16,23 +35,37 @@ index 1f949c1..aa002da 100755
1635
token.Rule( "ESCSQUOTE" ),
1736
token.Rule( "ANYCHAR" ),
1837
token.Rule( "QUOTE" ),
19-
@@ -162,6 +166,7 @@ exports.bnfRules = {
38+
@@ -162,6 +169,7 @@ exports.bnfRules = {
2039
//DO BE REMOVED IN THIS MAJOR VERSION! DO NOT USE!
2140
QEANYCHAR( token ){
2241
return token.Or( [
2342
+ token.Rule( "ESCSLASH" ),
2443
token.Rule( "ESCQUOTE" ),
2544
token.Rule( "ANYCHAR" ),
2645
token.Rule( "SQUOTE" ),
27-
@@ -186,6 +191,7 @@ exports.bnfRules = {
46+
@@ -186,6 +194,7 @@ exports.bnfRules = {
2847
//DO BE REMOVED IN THIS MAJOR VERSION! DO NOT USE!
2948
AQEANYCHAR( token ){
3049
return token.Or( [
3150
+ token.Rule( "ESCSLASH" ),
3251
token.Rule( "ESCAQUOTE" ),
3352
token.Rule( "ANYCHAR" ),
3453
token.Rule( "SQUOTE" ),
35-
@@ -285,7 +291,7 @@ exports.parserRules = {
54+
@@ -219,11 +228,12 @@ exports.bnfRules = {
55+
*/
56+
},
57+
AQLITERAL( token ){
58+
- return token.And( [
59+
+ const res = token.And( [
60+
token.Rule( "AQUOTE" ),
61+
token.Rule( "AQLITERALCHARS" ),
62+
token.Rule( "AQUOTE" )
63+
]);
64+
+ return res;
65+
},
66+
LITERAL( token ){
67+
return token.Or( [
68+
@@ -285,7 +295,7 @@ exports.parserRules = {
3669
}
3770
else{
3871
//This can be optimized @LHF
@@ -41,7 +74,7 @@ index 1f949c1..aa002da 100755
4174
for( let t = 0; t < token._tokenTrees[i].length; t++ ){
4275
for( let line in token._tokenTrees[i][t].expected ){
4376
for( let char in token._tokenTrees[i][t].expected[line] ){
44-
@@ -295,7 +301,7 @@ exports.parserRules = {
77+
@@ -295,7 +305,7 @@ exports.parserRules = {
4578
}
4679
}
4780
}
@@ -50,11 +83,24 @@ index 1f949c1..aa002da 100755
5083
token._tokenTrees[0] = [];
5184

5285
return false;
86+
diff --git a/node_modules/bnf/Script.js b/node_modules/bnf/Script.js
87+
index e5eb5b7..56bd641 100755
88+
--- a/node_modules/bnf/Script.js
89+
+++ b/node_modules/bnf/Script.js
90+
@@ -15,7 +15,7 @@ exports.Script = class Script{
91+
}
92+
93+
GetString( length, token ){
94+
- let str = this.rawScript.substring( token.point, token.point + length );
95+
+ let str = Buffer.from(this.rawScript).subarray( token.point, token.point + length ).toString('utf8');
96+
token.Seek( length );
97+
return str;
98+
}
5399
diff --git a/node_modules/bnf/Token.js b/node_modules/bnf/Token.js
54-
index f592ae5..d8fc55a 100755
100+
index f592ae5..c76e103 100755
55101
--- a/node_modules/bnf/Token.js
56102
+++ b/node_modules/bnf/Token.js
57-
@@ -226,13 +226,13 @@ exports.Token = class Token{
103+
@@ -226,16 +226,27 @@ exports.Token = class Token{
58104

59105
TryString( charBuffer ){
60106
let stringBuffer = Buffer.alloc( charBuffer.length );
@@ -70,3 +116,17 @@ index f592ae5..d8fc55a 100755
70116
return true;
71117
}
72118

119+
+ TryRe(pattern) {
120+
+ const mtch = this.script.scriptBuffer.subarray(this.point).toString('utf-8').match(pattern);
121+
+ if (mtch && mtch[0]) {
122+
+ const b = Buffer.from(mtch[0]);
123+
+ this.SetValue(mtch[0]);
124+
+ this.point+=b.length;
125+
+ return true;
126+
+ }
127+
+ return false;
128+
+ }
129+
+
130+
SetChar( char ){
131+
this.SetValue( this.GetChar() );
132+
this.point++;

test/parser.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ it('should compile', () => {
1919
expect(res).toBeTruthy()
2020
})
2121

22+
it('should compile log_stream_selector with ciryllic', () => {
23+
const scr = '{et_dolorem=`тететёąĄ`}'
24+
const script = bnf.ParseScript(scr)
25+
expect(script).toBeTruthy()
26+
})
27+
2228
it('should compile strings with escaped quotes', () => {
2329
const res = bnf.ParseScript('bytes_rate({run="kok\\"oko",u_ru_ru!="lolol",zozo=~"sssss"} |~"atltlt" !~ "rmrmrm" [5m])')
2430
expect(res.rootToken.Children('log_stream_selector_rule').map(c => c.value)).toEqual(

test/plugins.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ const { getPlg } = require('../plugins/engine')
33
it('should glob', () => {
44
expect(getPlg({ type: 'unwrap_registry' })).toBeTruthy()
55
})
6+
7+
it('should unicode chars', () => {
8+
console.log('АąŚĄ'.match(/\p{L}/ug))
9+
})

0 commit comments

Comments
 (0)