Skip to content

Commit e8bf368

Browse files
committed
parser correction
1 parent 352641c commit e8bf368

File tree

7 files changed

+484
-354
lines changed

7 files changed

+484
-354
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A JS module for data validation of complexly-structured-data.
88

99
```javascript
1010
<script type="module">
11-
import { DataValidator } from 'https://cdn.jsdelivr.net/gh/anshu-krishna/JS-Data-Validator-Advanced@1.1/src/data-validator-min.js';
11+
import { DataValidator } from 'https://cdn.jsdelivr.net/gh/anshu-krishna/JS-Data-Validator-Advanced@1.2/src/data-validator-min.js';
1212

1313
// Your code goes here
1414
</script>

src/data-validator-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/data-validator.js

Lines changed: 118 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*************************
2-
* Version: 1.1.1
2+
* Version: 1.2
33
*************************/
44
/*************************
55
* Other Functions / Classes
@@ -178,14 +178,7 @@ export class Ret {
178178
peg_c0 = "=>",
179179
peg_c1 = peg_literalExpectation("=>", false),
180180
peg_c2 = function (head, v) { return v; },
181-
peg_c3 = function (head, tail) {
182-
let chain = [head, ...tail];
183-
while (chain.length > 1) {
184-
const last = chain.pop();
185-
chain[chain.length - 1].nx = last;
186-
}
187-
return chain[0];
188-
},
181+
peg_c3 = function (head, tail) { return format_handler(head, tail); },
189182
peg_c4 = "|",
190183
peg_c5 = peg_literalExpectation("|", false),
191184
peg_c6 = function (head, v) { return v; },
@@ -525,7 +518,7 @@ export class Ret {
525518
let s0, s1, s2, s3, s4, s5, s6, s7, s8;
526519

527520
s0 = peg_currPos;
528-
s1 = peg_parse_();
521+
s1 = peg_parseORB();
529522
if (s1 !== peg_FAILED) {
530523
s2 = peg_parseType();
531524
if (s2 !== peg_FAILED) {
@@ -602,9 +595,15 @@ export class Ret {
602595
}
603596
}
604597
if (s3 !== peg_FAILED) {
605-
peg_savedPos = s0;
606-
s1 = peg_c3(s2, s3);
607-
s0 = s1;
598+
s4 = peg_parseCRB();
599+
if (s4 !== peg_FAILED) {
600+
peg_savedPos = s0;
601+
s1 = peg_c3(s2, s3);
602+
s0 = s1;
603+
} else {
604+
peg_currPos = s0;
605+
s0 = peg_FAILED;
606+
}
608607
} else {
609608
peg_currPos = s0;
610609
s0 = peg_FAILED;
@@ -619,11 +618,83 @@ export class Ret {
619618
}
620619
if (s0 === peg_FAILED) {
621620
s0 = peg_currPos;
622-
s1 = peg_parse_();
621+
s1 = peg_parseType();
623622
if (s1 !== peg_FAILED) {
624-
s2 = peg_parseType();
623+
s2 = [];
624+
s3 = peg_currPos;
625+
s4 = peg_parse_();
626+
if (s4 !== peg_FAILED) {
627+
if (input.substr(peg_currPos, 2) === peg_c0) {
628+
s5 = peg_c0;
629+
peg_currPos += 2;
630+
} else {
631+
s5 = peg_FAILED;
632+
if (peg_silentFails === 0) { peg_fail(peg_c1); }
633+
}
634+
if (s5 !== peg_FAILED) {
635+
s6 = peg_parse_();
636+
if (s6 !== peg_FAILED) {
637+
s7 = peg_parseType();
638+
if (s7 !== peg_FAILED) {
639+
peg_savedPos = s3;
640+
s4 = peg_c2(s1, s7);
641+
s3 = s4;
642+
} else {
643+
peg_currPos = s3;
644+
s3 = peg_FAILED;
645+
}
646+
} else {
647+
peg_currPos = s3;
648+
s3 = peg_FAILED;
649+
}
650+
} else {
651+
peg_currPos = s3;
652+
s3 = peg_FAILED;
653+
}
654+
} else {
655+
peg_currPos = s3;
656+
s3 = peg_FAILED;
657+
}
658+
while (s3 !== peg_FAILED) {
659+
s2.push(s3);
660+
s3 = peg_currPos;
661+
s4 = peg_parse_();
662+
if (s4 !== peg_FAILED) {
663+
if (input.substr(peg_currPos, 2) === peg_c0) {
664+
s5 = peg_c0;
665+
peg_currPos += 2;
666+
} else {
667+
s5 = peg_FAILED;
668+
if (peg_silentFails === 0) { peg_fail(peg_c1); }
669+
}
670+
if (s5 !== peg_FAILED) {
671+
s6 = peg_parse_();
672+
if (s6 !== peg_FAILED) {
673+
s7 = peg_parseType();
674+
if (s7 !== peg_FAILED) {
675+
peg_savedPos = s3;
676+
s4 = peg_c2(s1, s7);
677+
s3 = s4;
678+
} else {
679+
peg_currPos = s3;
680+
s3 = peg_FAILED;
681+
}
682+
} else {
683+
peg_currPos = s3;
684+
s3 = peg_FAILED;
685+
}
686+
} else {
687+
peg_currPos = s3;
688+
s3 = peg_FAILED;
689+
}
690+
} else {
691+
peg_currPos = s3;
692+
s3 = peg_FAILED;
693+
}
694+
}
625695
if (s2 !== peg_FAILED) {
626-
s1 = [s1, s2];
696+
peg_savedPos = s0;
697+
s1 = peg_c3(s1, s2);
627698
s0 = s1;
628699
} else {
629700
peg_currPos = s0;
@@ -633,6 +704,29 @@ export class Ret {
633704
peg_currPos = s0;
634705
s0 = peg_FAILED;
635706
}
707+
if (s0 === peg_FAILED) {
708+
s0 = peg_currPos;
709+
s1 = peg_parse_();
710+
if (s1 !== peg_FAILED) {
711+
s2 = peg_parseType();
712+
if (s2 !== peg_FAILED) {
713+
s3 = peg_parse_();
714+
if (s3 !== peg_FAILED) {
715+
s1 = [s1, s2, s3];
716+
s0 = s1;
717+
} else {
718+
peg_currPos = s0;
719+
s0 = peg_FAILED;
720+
}
721+
} else {
722+
peg_currPos = s0;
723+
s0 = peg_FAILED;
724+
}
725+
} else {
726+
peg_currPos = s0;
727+
s0 = peg_FAILED;
728+
}
729+
}
636730
}
637731

638732
return s0;
@@ -3252,6 +3346,14 @@ export class Ret {
32523346
if (ls !== null) { ret.ls = ls; }
32533347
return ret;
32543348
}
3349+
function format_handler(head, tail) {
3350+
let chain = [head, ...tail];
3351+
while (chain.length > 1) {
3352+
const last = chain.pop();
3353+
chain[chain.length - 1].nx = last;
3354+
}
3355+
return chain[0];
3356+
}
32553357

32563358

32573359
peg_result = peg_startRuleFunction();

src/peg/grammer EBNF.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
/* converted on Mon Apr 18, 2022, 14:21 (UTC+05:30) by pegjs-to-w3c v0.57 which is Copyright (c) 2011-2022 by Gunther Rademacher <[email protected]> */
1+
/* converted on Mon Apr 18, 2022, 15:05 (UTC+05:30) by pegjs-to-w3c v0.57 which is Copyright (c) 2011-2022 by Gunther Rademacher <[email protected]> */
22

3-
Format ::= _ Type ( _ '=>' _ Type )*
4-
Type ::= ( ORB Format ( _ '|' _ Format )* CRB | OSB ( ArrayFormat ( COMMA ArrayFormat )* COMMA? )? CSB | OCB ( IdfVal ( COMMA IdfVal )* )? ( COMMA '...' )? COMMA? CCB | Idf ) FuncList?
3+
Format ::= ORB Type ( _ '=>' _ Type )* CRB
4+
| Type ( _ '=>' _ Type )*
5+
| _ Type _
6+
Type ::= ORB Format ( _ '|' _ Format )* CRB FuncList?
7+
| OSB ( ArrayFormat ( COMMA ArrayFormat )* COMMA? )? CSB FuncList?
8+
| OCB ( IdfVal ( COMMA IdfVal )* )? ( COMMA '...' )? COMMA? CCB FuncList?
9+
| Idf FuncList?
510
IdfVal ::= '?'? ( Idf | String ) ( ORB _ '=' _ Value CRB )? COLON Format
611
ArrayFormat
712
::= MoreCount? Format
813
MoreCount
9-
::= ( '..' Number '..' | '...' ) _
10-
FuncList ::= Func+
14+
::= '..' Number '..' _
15+
| '...' _
16+
FuncList ::= Func Func*
1117
Func ::= _ '.' Idf ( ORB ValueList? COMMA? CRB )?
1218
Value ::= _ ( 'null' | 'undefined' | 'true' | 'false' | Number | String ) _
1319
| Object
@@ -32,7 +38,10 @@ CRB ::= _ ')' _
3238
<?TOKENS?>
3339

3440
Idf ::= $ [_a-z$] [0-9a-z$_]*
35-
Number ::= '-'? ( '0x' $ HexDigit+ | '0o' $ [0-7]+ | '0b' $ [0-1]+ | Digit+ ( '.' Digit+ )? ( [eE] ( '-' | '+' )? Digit+ )? )
41+
Number ::= '-'? '0x' $ HexDigit+
42+
| '-'? '0o' $ [0-7]+
43+
| '-'? '0b' $ [0-1]+
44+
| '-'? Digit+ ( '.' Digit+ )? ( [eE] ( '-' | '+' )? Digit+ )?
3645
String ::= '"' ( [^\"#x0-#x1F] | SpecialChar )* '"'
3746
| "'" ( [^\'#x0-#x1F] | SpecialChar )* "'"
3847
| '`' ( [^\`#x0-#x1F] | SpecialChar )* '`'
@@ -47,10 +56,12 @@ SpecialChar
4756
| '\r'
4857
| '\t'
4958
| '\0' $ [0-7] [0-7]? [0-7]?
50-
| ( '\x' $ | '\u' $ HexDigit HexDigit ) HexDigit HexDigit
51-
| [#xA#x9]
59+
| '\x' $ HexDigit HexDigit
60+
| '\u' $ HexDigit HexDigit HexDigit HexDigit
61+
| [#xA]
62+
| [#x9]
5263
_ ::= ( [ #x9#xA#xD] | Comment )*
5364
Comment ::= '/*' ( [^*] | '*' )* '*/'
54-
| '//' [^#xA]* #xA?
65+
| '//' [^#xA]* [#xA]?
5566
HexDigit ::= [0-9a-f]
5667
Digit ::= [0-9]

0 commit comments

Comments
 (0)