@ -18,9 +18,14 @@ describe( "compiler pass |generateBytecode|", function () {
}
function constsDetails ( consts ) {
function constsDetails ( literals, classes, expectati ons, func tion s ) {
return { consts : consts } ;
return {
literals : literals ,
classes : classes ,
expectations : expectations ,
functions : functions
} ;
}
@ -34,9 +39,9 @@ describe( "compiler pass |generateBytecode|", function () {
"c = 'c'"
] . join ( "\n" ) , {
rules : [
{ bytecode : [ 23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 ] } ,
{ bytecode : [ 23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 ] } ,
{ bytecode : [ 23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 ] }
{ bytecode : [ 23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 ] } ,
{ bytecode : [ 23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 ] } ,
{ bytecode : [ 23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 ] }
]
} ) ;
@ -48,14 +53,16 @@ describe( "compiler pass |generateBytecode|", function () {
"a = 'a'" ,
"b = 'b'" ,
"c = 'c'"
] . join ( "\n" ) , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"\"b\"" ,
"peg$literalExpectation(\"b\", false)" ,
"\"c\"" ,
"peg$literalExpectation(\"c\", false)"
] ) ) ;
] . join ( "\n" ) , constsDetails (
[ "a" , "b" , "c" ] ,
[ ] ,
[
{ type : "literal" , value : "a" , ignoreCase : false } ,
{ type : "literal" , value : "b" , ignoreCase : false } ,
{ type : "literal" , value : "c" , ignoreCase : false }
] ,
[ ]
) ) ;
} ) ;
@ -66,7 +73,7 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( "start = 'a'" , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
] ) ) ;
} ) ;
@ -92,13 +99,13 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar2 , bytecodeDetails ( [
23 , 0 , // EXPECT <0>
28 , // SILENT_FAILS_ON
18 , 1, 2 , 1 , 22 , 1 , 3 , // <expression>
18 , 0, 2 , 1 , 22 , 0 , 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>
20 , 0 , 2 , 1 , 21 , 1 , 3 , // <expression>
29 // SILENT_FAILS_OFF
] ) ) ;
@ -106,17 +113,24 @@ describe( "compiler pass |generateBytecode|", function () {
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]/"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar1 , constsDetails (
[ ] ,
[ ] ,
[ { type : "rule" , value : "start" } ] ,
[ ]
) ) ;
expect ( pass ) . to . changeAST ( grammar2 , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "rule" , value : "start" } ] ,
[ ]
) ) ;
expect ( pass ) . to . changeAST ( grammar3 , constsDetails (
[ ] ,
[ { value : [ "a" ] , inverted : false , ignoreCase : false } ] ,
[ { type : "rule" , value : "start" } ] ,
[ ]
) ) ;
} ) ;
@ -140,13 +154,15 @@ describe( "compiler pass |generateBytecode|", function () {
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 } ) ;
expect ( pass ) . to . changeAST ( grammar1 , constsDetails (
[ ] , [ ] , [ ] , [ ]
) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar2 , constsDetails (
[ "a" ] , [ ] , [ ] , [ ]
) , { } , { reportFailures : false } ) ;
expect ( pass ) . to . changeAST ( grammar3 , constsDetails (
[ ] , [ { value : [ "a" ] , inverted : false , ignoreCase : false } ] , [ ] , [ ]
) , { } , { reportFailures : false } ) ;
} ) ;
@ -159,13 +175,13 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( "start = 'a' / 'b' / 'c'" , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <alternatives[0]>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <alternatives[0]>
14 , 23 , 0 , // IF_ERROR
6 , // * POP
23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // <alternatives[1]>
23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 , // <alternatives[1]>
14 , 10 , 0 , // IF_ERROR
6 , // * POP
23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 // <alternatives[2]>
23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 // <alternatives[2]>
] ) ) ;
} ) ;
@ -182,10 +198,10 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
15 , 6 , 0 , // IF_NOT_ERROR
24 , 1 , // * LOAD_SAVED_POS
26 , 2 , 1 , 0 , // CALL
26 , 0 , 1 , 0 , // CALL <0>
9 // NIP
] ) ) ;
@ -193,11 +209,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"function() { code }"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ { predicate : false , params : [ ] , body : " code " } ]
) ) ;
} ) ;
@ -211,10 +228,10 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
15 , 7 , 0 , // IF_NOT_ERROR
24 , 1 , // * LOAD_SAVED_POS
26 , 2 , 1 , 1 , 0 , // CALL
26 , 0 , 1 , 1 , 0 , // CALL <0>
9 // NIP
] ) ) ;
@ -222,11 +239,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"function(a) { code }"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ { predicate : false , params : [ "a" ] , body : " code " } ]
) ) ;
} ) ;
@ -240,14 +258,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
15 , 41 , 3 , // IF_NOT_ERROR
23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[1]>
23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 , // * <elements[1]>
15 , 25 , 4 , // IF_NOT_ERROR
23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 , // * <elements[2]>
23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[2]>
15 , 9 , 4 , // IF_NOT_ERROR
24 , 3 , // * LOAD_SAVED_POS
26 , 6 , 4 , 3 , 2 , 1 , 0 , // CALL < 6 >
26 , 0 , 4 , 3 , 2 , 1 , 0 , // CALL < 0 >
8 , 3 , // * POP_N
7 , // POP_CURR_POS
3 , // PUSH_FAILED
@ -263,15 +281,16 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"\"b\"" ,
"peg$literalExpectation(\"b\", false)" ,
"\"c\"" ,
"peg$literalExpectation(\"c\", false)" ,
"function(a, b, c) { code }"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" , "b" , "c" ] ,
[ ] ,
[
{ type : "literal" , value : "a" , ignoreCase : false } ,
{ type : "literal" , value : "b" , ignoreCase : false } ,
{ type : "literal" , value : "c" , ignoreCase : false }
] ,
[ { predicate : false , params : [ "a" , "b" , "c" ] , body : " code " } ]
) ) ;
} ) ;
@ -287,11 +306,11 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
15 , 35 , 3 , // IF_NOT_ERROR
23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[1]>
23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 , // * <elements[1]>
15 , 19 , 4 , // IF_NOT_ERROR
23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 , // * <elements[2]>
23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[2]>
15 , 3 , 4 , // IF_NOT_ERROR
11 , 3 , // * WRAP
9 , // NIP
@ -310,14 +329,16 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"\"b\"" ,
"peg$literalExpectation(\"b\", false)" ,
"\"c\"" ,
"peg$literalExpectation(\"c\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" , "b" , "c" ] ,
[ ] ,
[
{ type : "literal" , value : "a" , ignoreCase : false } ,
{ type : "literal" , value : "b" , ignoreCase : false } ,
{ type : "literal" , value : "c" , ignoreCase : false }
] ,
[ ]
) ) ;
} ) ;
@ -328,7 +349,7 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( "start = a:'a'" , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
] ) ) ;
} ) ;
@ -341,7 +362,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( "start = $'a'" , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
15 , 2 , 1 , // IF_NOT_ERROR
6 , // * POP
12 , // TEXT
@ -361,7 +382,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
38 , // EXPECT_NS_BEGIN
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
39 , 0 , // EXPECT_NS_END <false>
15 , 3 , 3 , // IF_NOT_ERROR
6 , // * POP
@ -376,10 +397,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -394,7 +417,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
38 , // EXPECT_NS_BEGIN
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
39 , 1 , // EXPECT_NS_END <true>
14 , 3 , 3 , // IF_ERROR
6 , // * POP
@ -409,10 +432,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -425,7 +450,7 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
14 , 2 , 0 , // IF_ERROR
6 , // * POP
2 // PUSH_NULL
@ -435,10 +460,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -452,10 +479,10 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
4 , // PUSH_EMPTY_ARRAY
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
16 , 10 , // WHILE_NOT_ERROR
10 , // * APPEND
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
6 // POP
] ) ) ;
@ -463,10 +490,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -480,11 +509,11 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
4 , // PUSH_EMPTY_ARRAY
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
15 , 13 , 3 , // IF_NOT_ERROR
16 , 10 , // * WHILE_NOT_ERROR
10 , // * APPEND
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <expression>
6 , // POP
6 , // * POP
6 , // POP
@ -495,10 +524,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -511,17 +542,19 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 // <expression>
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;
@ -537,7 +570,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
25 , // UPDATE_SAVED_POS
26 , 0 , 0 , 0 , // CALL
26 , 0 , 0 , 0 , // CALL <0>
13 , 2 , 2 , // IF
6 , // * POP
1 , // PUSH_UNDEFINED
@ -551,7 +584,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST (
grammar ,
constsDetails ( [ "function() { code }" ] )
constsDetails ( [ ] , [ ] , [ ] , [ { predicate : true , params : [ ] , body : " code " } ] )
) ;
} ) ;
@ -566,14 +599,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
15 , 57 , 3 , // IF_NOT_ERROR
23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[1]>
23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 , // * <elements[1]>
15 , 41 , 4 , // IF_NOT_ERROR
23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 , // * <elements[2]>
23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[2]>
15 , 25 , 4 , // IF_NOT_ERROR
25 , // * UPDATE_SAVED_POS
26 , 6 , 0 , 3 , 2 , 1 , 0 , // CALL
26 , 0 , 0 , 3 , 2 , 1 , 0 , // CALL <0>
13 , 2 , 2 , // IF
6 , // * POP
1 , // PUSH_UNDEFINED
@ -600,15 +633,16 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"\"b\"" ,
"peg$literalExpectation(\"b\", false)" ,
"\"c\"" ,
"peg$literalExpectation(\"c\", false)" ,
"function(a, b, c) { code }"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" , "b" , "c" ] ,
[ ] ,
[
{ type : "literal" , value : "a" , ignoreCase : false } ,
{ type : "literal" , value : "b" , ignoreCase : false } ,
{ type : "literal" , value : "c" , ignoreCase : false }
] ,
[ { predicate : true , params : [ "a" , "b" , "c" ] , body : " code " } ]
) ) ;
} ) ;
@ -626,7 +660,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
25 , // UPDATE_SAVED_POS
26 , 0 , 0 , 0 , // CALL
26 , 0 , 0 , 0 , // CALL <0>
13 , 2 , 2 , // IF
6 , // * POP
3 , // PUSH_FAILED
@ -640,7 +674,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST (
grammar ,
constsDetails ( [ "function() { code }" ] )
constsDetails ( [ ] , [ ] , [ ] , [ { predicate : true , params : [ ] , body : " code " } ] )
) ;
} ) ;
@ -655,14 +689,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
5 , // PUSH_CURR_POS
23 , 1 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
23 , 0 , 18 , 0 , 2 , 1 , 22 , 0 , 3 , // <elements[0]>
15 , 57 , 3 , // IF_NOT_ERROR
23 , 3, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[1]>
23 , 1, 18 , 1 , 2 , 1 , 22 , 1 , 3 , // * <elements[1]>
15 , 41 , 4 , // IF_NOT_ERROR
23 , 5, 18 , 4 , 2 , 1 , 22 , 4 , 3 , // * <elements[2]>
23 , 2, 18 , 2 , 2 , 1 , 22 , 2 , 3 , // * <elements[2]>
15 , 25 , 4 , // IF_NOT_ERROR
25 , // * UPDATE_SAVED_POS
26 , 6 , 0 , 3 , 2 , 1 , 0 , // CALL
26 , 0 , 0 , 3 , 2 , 1 , 0 , // CALL <0>
13 , 2 , 2 , // IF
6 , // * POP
3 , // PUSH_FAILED
@ -689,15 +723,16 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)" ,
"\"b\"" ,
"peg$literalExpectation(\"b\", false)" ,
"\"c\"" ,
"peg$literalExpectation(\"c\", false)" ,
"function(a, b, c) { code }"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" , "b" , "c" ] ,
[ ] ,
[
{ type : "literal" , value : "a" , ignoreCase : false } ,
{ type : "literal" , value : "b" , ignoreCase : false } ,
{ type : "literal" , value : "c" , ignoreCase : false }
] ,
[ { predicate : true , params : [ "a" , "b" , "c" ] , body : " code " } ]
) ) ;
} ) ;
@ -736,14 +771,14 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
0 , 0 // PUSH
0 // PUSH _EMPTY_STRING
] ) ) ;
} ) ;
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [ "\"\"" ] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [ ] , [ ] , [ ] , [ ] ) ) ;
} ) ;
@ -756,9 +791,9 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "generates correct bytecode" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , bytecodeDetails ( [
23 , 1, // EXPECT <1 >
23 , 0, // EXPECT <0 >
18 , 0 , 2 , 1 , // MATCH_STRING <0>
22 , 0 , // * ACCEPT_STRING
22 , 0 , // * ACCEPT_STRING <0>
3 // * PUSH_FAILED
] ) ) ;
@ -766,10 +801,12 @@ describe( "compiler pass |generateBytecode|", function () {
it ( "defines correct constants" , function ( ) {
expect ( pass ) . to . changeAST ( grammar , constsDetails ( [
"\"a\"" ,
"peg$literalExpectation(\"a\", false)"
] ) ) ;
expect ( pass ) . to . changeAST ( grammar , constsDetails (
[ "a" ] ,
[ ] ,
[ { type : "literal" , value : "a" , ignoreCase : false } ] ,
[ ]
) ) ;
} ) ;