@ -75,26 +75,80 @@ describe( "compiler pass |generateBytecode|", function () {
describe ( "for named" , function ( ) {
const grammar = "start 'start' = 'a'" ;
const grammar1 = "start 'start' = ." ;
const grammar2 = "start 'start' = 'a'" ;
const grammar3 = "start 'start' = [a]" ;
it ( "generates correct bytecode" , function ( ) {
describe( "when |reportFailures=true| ", function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
28 , // SILENT_FAILS_ON
23 , 2 , 18 , 1 , 2 , 1 , 22 , 1 , 3 , // <expression>
29 // SILENT_FAILS_OFF
] ) ) ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar1 , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
28 , // SILENT_FAILS_ON
17 , 2 , 1 , 21 , 1 , 3 , // <expression>
29 // SILENT_FAILS_OFF
] ) ) ;
expect ( pass ) . to . changeAST ( grammar2 , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
28 , // SILENT_FAILS_ON
18 , 1 , 2 , 1 , 22 , 1 , 3 , // <expression>
29 // SILENT_FAILS_OFF
] ) ) ;
expect ( pass ) . to . changeAST ( grammar3 , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
28 , // SILENT_FAILS_ON
20 , 1 , 2 , 1 , 21 , 1 , 3 , // <expression>
29 // SILENT_FAILS_OFF
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar1 , constsDetails ( [
"peg$otherExpectation(\"start\")"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar2 , constsDetails ( [
"peg$otherExpectation(\"start\")" ,
"\"a\""
] ) ) ;
expect ( pass ) . to . changeAST ( grammar3 , constsDetails ( [
"peg$otherExpectation(\"start\")" ,
"/^[a]/"
] ) ) ;
} ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
describe( "when |reportFailures=false| ", function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"peg$otherExpectation(\"start\")" ,
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar1 , bytecodeDetails ( [
17 , 2 , 1 , 21 , 1 , 3 , // <expression>
] ) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar2 , bytecodeDetails ( [
18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
] ) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar3 , bytecodeDetails ( [
20 , 0 , 2 , 1 , 21 , 1 , 3 , // <expression>
] ) , { } , { reportFailures : false } ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar1 , constsDetails ( [ ] ) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar2 , constsDetails ( [
"\"a\""
] ) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar3 , constsDetails ( [
"/^[a]/"
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
@ -452,14 +506,25 @@ describe( "compiler pass |generateBytecode|", function () {
describe ( "for group" , function ( ) {
const grammar = "start = ('a')" ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( "start = ('a')" , bytecodeDetails ( [
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
} ) ;
} ) ;
describe ( "for semantic_and" , function ( ) {
@ -662,140 +727,282 @@ describe( "compiler pass |generateBytecode|", function () {
describe ( "for literal" , function ( ) {
describe ( " empty ", function ( ) {
describe ( " when |reportFailures=true| ", function ( ) {
const grammar = "start = ''" ;
describe ( "empty" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
const grammar = "start = ''" ;
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
0 , 0 // PUSH
] ) ) ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
0 , 0 // PUSH
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [ "\"\"" ] ) ) ;
} ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
describe ( "non-empty case-sensitive" , function ( ) {
const grammar = "start = 'a'" ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , // EXPECT <1>
18 , 0 , 2 , 1 , // MATCH_STRING <0>
22 , 0 , // * ACCEPT_STRING
3 // * PUSH_FAILED
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
} ) ;
} ) ;
describe ( "non-empty case-insensitive" , function ( ) {
const grammar = "start = 'A'i" ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , // EXPECT <1>
19 , 0 , 2 , 1 , // MATCH_STRING_IC <0>
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) ) ;
} ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [ "\"\"" ] ) ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"A\", true)"
] ) ) ;
} ) ;
} ) ;
} ) ;
describe ( "non-empty case-sensitive" , function ( ) {
describe ( " when |reportFailures=false| ", function ( ) {
const grammar = "start = 'a'" ;
describe ( "empty" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
const grammar = "start = ''" ;
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , // EXPECT <1>
18 , 0 , 2 , 1 , // MATCH_STRING <0>
22 , 0 , // * ACCEPT_STRING
3 // * PUSH_FAILED
] ) ) ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
0 , 0 // PUSH
] ) , { } , { reportFailures : false } ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [ "\"\"" ] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
describe( "non-empty case-sensitive ", function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
const grammar = "start = 'a'" ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
18 , 0 , 2 , 1 , // MATCH_STRING <0>
22 , 0 , // * ACCEPT_STRING
3 // * PUSH_FAILED
] ) , { } , { reportFailures : false } ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\""
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
describe ( "non-empty case-insensitive" , function ( ) {
const grammar = "start = 'A'i" ;
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
19 , 0 , 2 , 1 , // MATCH_STRING_IC <0>
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) , { } , { reportFailures : false } ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\""
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
} ) ;
describe ( "non-empty case-insensitive" , function ( ) {
} ) ;
describe ( "for class" , function ( ) {
const grammar = "start = 'A'i" ;
describe ( "when |reportFailures=true|" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
expect ( pass ) . to . changeAST ( "start = [a]" , bytecodeDetails ( [
23 , 1 , // EXPECT <1>
19 , 0 , 2 , 1 , // MATCH_STRING_IC <0>
20, 0 , 2 , 1 , // MATCH_REGEXP <0>
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
describe( "non-inverted case-sensitive ", function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"A\", true)"
] ) ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]" , constsDetails ( [
"/^[a]/" ,
"peg$classExpectation([\"a\"], false, false)"
] ) ) ;
} ) ;
} ) ;
} ) ;
describe ( "inverted case-sensitive" , function ( ) {
} ) ;
it ( "defines correct constants" , function ( ) {
describe ( "for class" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [^a]" , constsDetails ( [
"/^[^a]/" ,
"peg$classExpectation([\"a\"], true, false)"
] ) ) ;
it ( "generates correct bytecode" , function ( ) {
} ) ;
expect ( pass ) . to . changeAST ( "start = [a]" , bytecodeDetails ( [
23 , 1 , // EXPECT <1>
20 , 0 , 2 , 1 , // MATCH_REGEXP <0>
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) ) ;
} ) ;
} ) ;
describe ( "non-inverted case-insensitive" , function ( ) {
describe ( "non-inverted case-sensitive ", function ( ) {
it ( "defines correct constants" , function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]i" , constsDetails ( [
"/^[a]/i" ,
"peg$classExpectation([\"a\"], false, true)"
] ) ) ;
expect ( pass ) . to . changeAST ( "start = [a]" , constsDetails ( [
"/^[a]/" ,
"peg$classExpectation([\"a\"], false, false)"
] ) ) ;
} ) ;
} ) ;
} ) ;
describe ( "complex" , function ( ) {
describe ( "inverted case-sensitive ", function ( ) {
it ( "defines correct constants ", function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [ab-def-hij-l]" , constsDetails ( [
"/^[ab-def-hij-l]/" ,
"peg$classExpectation([\"a\", [\"b\", \"d\"], \"e\", [\"f\", \"h\"], \"i\", [\"j\", \"l\"]], false, false)"
] ) ) ;
expect ( pass ) . to . changeAST ( "start = [^a]" , constsDetails ( [
"/^[^a]/" ,
"peg$classExpectation([\"a\"], true, false)"
] ) ) ;
} ) ;
} ) ;
} ) ;
describe ( " non-inverted case-insensitive ", function ( ) {
describe ( " when |reportFailures=false| ", function ( ) {
it ( " defines correct constants ", function ( ) {
it ( " generates correct bytecode ", function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]i" , constsDetails ( [
"/^[a]/i" ,
"peg$classExpectation([\"a\"], false, true)"
] ) ) ;
expect ( pass ) . to . changeAST ( "start = [a]" , bytecodeDetails ( [
20 , 0 , 2 , 1 , // MATCH_REGEXP <0>
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
describe ( "non-inverted case-sensitive" , function ( ) {
describe ( "complex ", function ( ) {
it ( "defines correct constants ", function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]" , constsDetails ( [
"/^[a]/"
] ) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( "start = [ab-def-hij-l]" , constsDetails ( [
"/^[ab-def-hij-l]/" ,
"peg$classExpectation([\"a\", [\"b\", \"d\"], \"e\", [\"f\", \"h\"], \"i\", [\"j\", \"l\"]], false, false)"
] ) ) ;
} ) ;
} ) ;
describe ( "inverted case-sensitive" , function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [^a]" , constsDetails ( [
"/^[^a]/"
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
describe ( "non-inverted case-insensitive" , function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]i" , constsDetails ( [
"/^[a]/i"
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
describe ( "complex" , function ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [ab-def-hij-l]" , constsDetails ( [
"/^[ab-def-hij-l]/"
] ) , { } , { reportFailures : false } ) ;
} ) ;
} ) ;
@ -805,25 +1012,56 @@ describe( "compiler pass |generateBytecode|", function () {
describe ( "for any" , function ( ) {
const grammar = "start = ." ;
describe ( "when |reportFailures=true|" , function ( ) {
it ( "generates bytecode" , function ( ) {
const grammar = "start = ." ;
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
17 , 2 , 1 , // MATCH_ANY
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) ) ;
it ( "generates bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
17 , 2 , 1 , // MATCH_ANY
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST (
grammar ,
constsDetails ( [ "peg$anyExpectation()" ] )
) ;
} ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
describe ( "when |reportFailures=false|" , function ( ) {
const grammar = "start = ." ;
expect ( pass ) . to . changeAST (
grammar ,
constsDetails ( [ "peg$anyExpectation()" ] )
) ;
it ( "generates bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
17 , 2 , 1 , // MATCH_ANY
21 , 1 , // * ACCEPT_N
3 // * PUSH_FAILED
] ) , { } , { reportFailures : false } ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST (
grammar ,
constsDetails ( [ ] ) ,
{ } ,
{ reportFailures : false }
) ;
} ) ;
} ) ;