@ -75,14 +75,30 @@ 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]" ;
describe ( "when |reportFailures=true|" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
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
23 , 2 , 18 , 1 , 2 , 1 , 22 , 1 , 3 , // <expression>
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
] ) ) ;
@ -90,16 +106,54 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
expect ( pass ) . to . changeAST ( grammar1 , constsDetails ( [
"peg$otherExpectation(\"start\")"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar2 , constsDetails ( [
"peg$otherExpectation(\"start\")" ,
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
"\"a\""
] ) ) ;
expect ( pass ) . to . changeAST ( grammar3 , constsDetails ( [
"peg$otherExpectation(\"start\")" ,
"/^[a]/"
] ) ) ;
} ) ;
} ) ;
describe ( "when |reportFailures=false|" , function ( ) {
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 } ) ;
} ) ;
} ) ;
} ) ;
describe ( "for choice" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
@ -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,6 +727,8 @@ describe( "compiler pass |generateBytecode|", function () {
describe ( "for literal" , function ( ) {
describe ( "when |reportFailures=true|" , function ( ) {
describe ( "empty" , function ( ) {
const grammar = "start = ''" ;
@ -736,8 +803,84 @@ describe( "compiler pass |generateBytecode|", function () {
} ) ;
describe ( "when |reportFailures=false|" , function ( ) {
describe ( "empty" , function ( ) {
const grammar = "start = ''" ;
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 } ) ;
} ) ;
} ) ;
describe ( "non-empty case-sensitive" , function ( ) {
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 ( "for class" , function ( ) {
describe ( "when |reportFailures=true|" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]" , bytecodeDetails ( [
@ -803,8 +946,74 @@ describe( "compiler pass |generateBytecode|", function () {
} ) ;
describe ( "when |reportFailures=false|" , function ( ) {
it ( "generates correct bytecode" , function ( ) {
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 ( ) {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( "start = [a]" , constsDetails ( [
"/^[a]/"
] ) , { } , { reportFailures : 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 } ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( "for any" , function ( ) {
describe ( "when |reportFailures=true|" , function ( ) {
const grammar = "start = ." ;
it ( "generates bytecode" , function ( ) {
@ -829,4 +1038,33 @@ describe( "compiler pass |generateBytecode|", function () {
} ) ;
describe ( "when |reportFailures=false|" , function ( ) {
const grammar = "start = ." ;
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 }
) ;
} ) ;
} ) ;
} ) ;
} ) ;