You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1184 lines
41 KiB
JavaScript
1184 lines
41 KiB
JavaScript
10 years ago
|
"use strict";
|
||
|
|
||
7 years ago
|
const chai = require( "chai" );
|
||
|
const helpers = require( "./helpers" );
|
||
6 years ago
|
const pass = require( "pegjs" ).compiler.passes.generate.generateBytecode;
|
||
7 years ago
|
|
||
|
chai.use( helpers );
|
||
|
|
||
|
const expect = chai.expect;
|
||
|
|
||
|
describe( "compiler pass |generateBytecode|", function () {
|
||
|
|
||
|
function bytecodeDetails( bytecode ) {
|
||
|
|
||
|
return {
|
||
|
rules: [ { bytecode: bytecode } ]
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
7 years ago
|
function constsDetails( literals, classes, expectations, functions ) {
|
||
7 years ago
|
|
||
7 years ago
|
return {
|
||
|
literals: literals,
|
||
|
classes: classes,
|
||
|
expectations: expectations,
|
||
|
functions: functions
|
||
|
};
|
||
7 years ago
|
|
||
|
}
|
||
|
|
||
|
describe( "for grammar", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( [
|
||
|
"a = 'a'",
|
||
|
"b = 'b'",
|
||
|
"c = 'c'"
|
||
|
].join( "\n" ), {
|
||
|
rules: [
|
||
7 years ago
|
{ 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 ] }
|
||
7 years ago
|
]
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( [
|
||
|
"a = 'a'",
|
||
|
"b = 'b'",
|
||
|
"c = 'c'"
|
||
7 years ago
|
].join( "\n" ), constsDetails(
|
||
|
[ "a", "b", "c" ],
|
||
|
[],
|
||
|
[
|
||
|
{ type: "literal", value: "a", ignoreCase: false },
|
||
|
{ type: "literal", value: "b", ignoreCase: false },
|
||
|
{ type: "literal", value: "c", ignoreCase: false }
|
||
|
],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for rule", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = 'a'", bytecodeDetails( [
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression>
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for named", function () {
|
||
|
|
||
7 years ago
|
const grammar1 = "start 'start' = .";
|
||
|
const grammar2 = "start 'start' = 'a'";
|
||
|
const grammar3 = "start 'start' = [a]";
|
||
7 years ago
|
|
||
7 years ago
|
describe( "when |reportFailures=true|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
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
|
||
7 years ago
|
18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
29 // SILENT_FAILS_OFF
|
||
|
] ) );
|
||
|
expect( pass ).to.changeAST( grammar3, bytecodeDetails( [
|
||
|
23, 0, // EXPECT <0>
|
||
|
28, // SILENT_FAILS_ON
|
||
7 years ago
|
20, 0, 2, 1, 21, 1, 3, // <expression>
|
||
7 years ago
|
29 // SILENT_FAILS_OFF
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
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" } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=false|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
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 () {
|
||
|
|
||
7 years ago
|
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 } );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for choice", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = 'a' / 'b' / 'c'", bytecodeDetails( [
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <alternatives[0]>
|
||
7 years ago
|
14, 23, 0, // IF_ERROR
|
||
|
6, // * POP
|
||
7 years ago
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // <alternatives[1]>
|
||
7 years ago
|
14, 10, 0, // IF_ERROR
|
||
|
6, // * POP
|
||
7 years ago
|
23, 2, 18, 2, 2, 1, 22, 2, 3 // <alternatives[2]>
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for action", function () {
|
||
|
|
||
|
describe( "without labels", function () {
|
||
|
|
||
|
const grammar = "start = 'a' { code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
15, 6, 0, // IF_NOT_ERROR
|
||
|
24, 1, // * LOAD_SAVED_POS
|
||
7 years ago
|
26, 0, 1, 0, // CALL <0>
|
||
7 years ago
|
9 // NIP
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[ { predicate: false, params: [], body: " code " } ]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "with one label", function () {
|
||
|
|
||
|
const grammar = "start = a:'a' { code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
15, 7, 0, // IF_NOT_ERROR
|
||
|
24, 1, // * LOAD_SAVED_POS
|
||
7 years ago
|
26, 0, 1, 1, 0, // CALL <0>
|
||
7 years ago
|
9 // NIP
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[ { predicate: false, params: [ "a" ], body: " code " } ]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "with multiple labels", function () {
|
||
|
|
||
|
const grammar = "start = a:'a' b:'b' c:'c' { code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
7 years ago
|
15, 41, 3, // IF_NOT_ERROR
|
||
7 years ago
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
7 years ago
|
15, 25, 4, // IF_NOT_ERROR
|
||
7 years ago
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
7 years ago
|
15, 9, 4, // IF_NOT_ERROR
|
||
|
24, 3, // * LOAD_SAVED_POS
|
||
7 years ago
|
26, 0, 4, 3, 2, 1, 0, // CALL <0>
|
||
7 years ago
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
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 " } ]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for sequence", function () {
|
||
|
|
||
|
const grammar = "start = 'a' 'b' 'c'";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
7 years ago
|
15, 35, 3, // IF_NOT_ERROR
|
||
7 years ago
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
7 years ago
|
15, 19, 4, // IF_NOT_ERROR
|
||
7 years ago
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
7 years ago
|
15, 3, 4, // IF_NOT_ERROR
|
||
|
11, 3, // * WRAP
|
||
|
9, // NIP
|
||
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
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 }
|
||
|
],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
6 years ago
|
it( "generates correct plucking bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = 'a' @'b' 'c'", bytecodeDetails( [
|
||
|
5, // PUSH_CURR_POS
|
||
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
|
15, 36, 3, // IF_NOT_ERROR
|
||
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
|
15, 20, 4, // IF_NOT_ERROR
|
||
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
|
15, 4, 4, // IF_NOT_ERROR
|
||
|
41, 4, 1, 1, // * PLUCK
|
||
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = 'a' @'b' @'c'", bytecodeDetails( [
|
||
|
5, // PUSH_CURR_POS
|
||
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
|
15, 37, 3, // IF_NOT_ERROR
|
||
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
|
15, 21, 4, // IF_NOT_ERROR
|
||
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
|
15, 5, 4, // IF_NOT_ERROR
|
||
|
41, 4, 2, 1, 0, // * PLUCK
|
||
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
} );
|
||
|
|
||
|
describe( "for labeled", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = a:'a'", bytecodeDetails( [
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression>
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for text", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( "start = $'a'", bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
15, 2, 1, // IF_NOT_ERROR
|
||
|
6, // * POP
|
||
|
12, // TEXT
|
||
|
9 // * NIP
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for simple_and", function () {
|
||
|
|
||
|
const grammar = "start = &'a'";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
|
38, // EXPECT_NS_BEGIN
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
39, 0, // EXPECT_NS_END <false>
|
||
|
15, 3, 3, // IF_NOT_ERROR
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
1, // PUSH_UNDEFINED
|
||
|
6, // * POP
|
||
|
6, // POP
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for simple_not", function () {
|
||
|
|
||
|
const grammar = "start = !'a'";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
|
38, // EXPECT_NS_BEGIN
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
39, 1, // EXPECT_NS_END <true>
|
||
|
14, 3, 3, // IF_ERROR
|
||
|
6, // * POP
|
||
|
6, // POP
|
||
|
1, // PUSH_UNDEFINED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for optional", function () {
|
||
|
|
||
|
const grammar = "start = 'a'?";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
14, 2, 0, // IF_ERROR
|
||
|
6, // * POP
|
||
|
2 // PUSH_NULL
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for zero_or_more", function () {
|
||
|
|
||
|
const grammar = "start = 'a'*";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
4, // PUSH_EMPTY_ARRAY
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
16, 10, // WHILE_NOT_ERROR
|
||
|
10, // * APPEND
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
6 // POP
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for one_or_more", function () {
|
||
|
|
||
|
const grammar = "start = 'a'+";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
4, // PUSH_EMPTY_ARRAY
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
15, 13, 3, // IF_NOT_ERROR
|
||
|
16, 10, // * WHILE_NOT_ERROR
|
||
|
10, // * APPEND
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
|
||
7 years ago
|
6, // POP
|
||
|
6, // * POP
|
||
|
6, // POP
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for group", function () {
|
||
|
|
||
7 years ago
|
const grammar = "start = ('a')";
|
||
|
|
||
7 years ago
|
it( "generates correct bytecode", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression>
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
} );
|
||
|
|
||
|
describe( "for semantic_and", function () {
|
||
|
|
||
|
describe( "without labels", function () {
|
||
|
|
||
|
const grammar = "start = &{ code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
|
25, // UPDATE_SAVED_POS
|
||
7 years ago
|
26, 0, 0, 0, // CALL <0>
|
||
7 years ago
|
13, 2, 2, // IF
|
||
|
6, // * POP
|
||
|
1, // PUSH_UNDEFINED
|
||
|
6, // * POP
|
||
|
3 // PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST(
|
||
|
grammar,
|
||
7 years ago
|
constsDetails( [], [], [], [ { predicate: true, params: [], body: " code " } ] )
|
||
7 years ago
|
);
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "with labels", function () {
|
||
|
|
||
|
const grammar = "start = a:'a' b:'b' c:'c' &{ code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
7 years ago
|
15, 57, 3, // IF_NOT_ERROR
|
||
7 years ago
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
7 years ago
|
15, 41, 4, // IF_NOT_ERROR
|
||
7 years ago
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
7 years ago
|
15, 25, 4, // IF_NOT_ERROR
|
||
|
25, // * UPDATE_SAVED_POS
|
||
7 years ago
|
26, 0, 0, 3, 2, 1, 0, // CALL <0>
|
||
7 years ago
|
13, 2, 2, // IF
|
||
|
6, // * POP
|
||
|
1, // PUSH_UNDEFINED
|
||
|
6, // * POP
|
||
|
3, // PUSH_FAILED
|
||
|
15, 3, 4, // IF_NOT_ERROR
|
||
|
11, 4, // * WRAP
|
||
|
9, // NIP
|
||
|
8, 4, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
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 " } ]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for semantic_not", function () {
|
||
|
|
||
|
describe( "without labels", function () {
|
||
|
|
||
|
const grammar = "start = !{ code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
|
25, // UPDATE_SAVED_POS
|
||
7 years ago
|
26, 0, 0, 0, // CALL <0>
|
||
7 years ago
|
13, 2, 2, // IF
|
||
|
6, // * POP
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
1 // PUSH_UNDEFINED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST(
|
||
|
grammar,
|
||
7 years ago
|
constsDetails( [], [], [], [ { predicate: true, params: [], body: " code " } ] )
|
||
7 years ago
|
);
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "with labels", function () {
|
||
|
|
||
|
const grammar = "start = a:'a' b:'b' c:'c' !{ code }";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
5, // PUSH_CURR_POS
|
||
7 years ago
|
23, 0, 18, 0, 2, 1, 22, 0, 3, // <elements[0]>
|
||
7 years ago
|
15, 57, 3, // IF_NOT_ERROR
|
||
7 years ago
|
23, 1, 18, 1, 2, 1, 22, 1, 3, // * <elements[1]>
|
||
7 years ago
|
15, 41, 4, // IF_NOT_ERROR
|
||
7 years ago
|
23, 2, 18, 2, 2, 1, 22, 2, 3, // * <elements[2]>
|
||
7 years ago
|
15, 25, 4, // IF_NOT_ERROR
|
||
|
25, // * UPDATE_SAVED_POS
|
||
7 years ago
|
26, 0, 0, 3, 2, 1, 0, // CALL <0>
|
||
7 years ago
|
13, 2, 2, // IF
|
||
|
6, // * POP
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
1, // PUSH_UNDEFINED
|
||
|
15, 3, 4, // IF_NOT_ERROR
|
||
|
11, 4, // * WRAP
|
||
|
9, // NIP
|
||
|
8, 4, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 3, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
8, 2, // * POP_N
|
||
|
7, // POP_CURR_POS
|
||
|
3, // PUSH_FAILED
|
||
|
6, // * POP
|
||
|
7, // POP_CURR_POS
|
||
|
3 // PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
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 " } ]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for rule_ref", function () {
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( [
|
||
|
"start = other",
|
||
|
"other = 'other'"
|
||
|
].join( "\n" ), {
|
||
|
rules: [
|
||
|
{
|
||
|
bytecode: [ 27, 1 ] // RULE
|
||
|
},
|
||
|
{ }
|
||
|
]
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for literal", function () {
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=true|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
describe( "empty", function () {
|
||
7 years ago
|
|
||
7 years ago
|
const grammar = "start = ''";
|
||
7 years ago
|
|
||
7 years ago
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
0 // PUSH_EMPTY_STRING
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails( [], [], [], [] ) );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "non-empty case-sensitive", function () {
|
||
|
|
||
|
const grammar = "start = 'a'";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
23, 0, // EXPECT <0>
|
||
7 years ago
|
18, 0, 2, 1, // MATCH_STRING <0>
|
||
7 years ago
|
22, 0, // * ACCEPT_STRING <0>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "a", ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "non-empty case-insensitive", function () {
|
||
|
|
||
|
const grammar = "start = 'A'i";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
23, 0, // EXPECT <0>
|
||
7 years ago
|
19, 0, 2, 1, // MATCH_STRING_IC <0>
|
||
7 years ago
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ],
|
||
|
[],
|
||
|
[ { type: "literal", value: "A", ignoreCase: true } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=false|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
describe( "empty", function () {
|
||
7 years ago
|
|
||
7 years ago
|
const grammar = "start = ''";
|
||
7 years ago
|
|
||
7 years ago
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
7 years ago
|
0 // PUSH_EMPTY_STRING
|
||
7 years ago
|
] ), {}, { reportFailures: false } );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails( [], [], [], [] ), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "non-empty case-sensitive", function () {
|
||
7 years ago
|
|
||
7 years ago
|
const grammar = "start = 'a'";
|
||
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
|
18, 0, 2, 1, // MATCH_STRING <0>
|
||
7 years ago
|
22, 0, // * ACCEPT_STRING <0>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ), {}, { reportFailures: false } );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ], [], [], []
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
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>
|
||
7 years ago
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ), {}, { reportFailures: false } );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( grammar, constsDetails(
|
||
|
[ "a" ], [], [], []
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
} );
|
||
|
|
||
|
describe( "for class", function () {
|
||
7 years ago
|
|
||
7 years ago
|
describe( "when |reportFailures=true|", function () {
|
||
7 years ago
|
|
||
|
it( "generates correct bytecode", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]", bytecodeDetails( [
|
||
7 years ago
|
23, 0, // EXPECT <0>
|
||
|
20, 0, 2, 1, // MATCH_CLASS <0>
|
||
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
7 years ago
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "non-inverted case-sensitive", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]", constsDetails(
|
||
|
[],
|
||
|
[ { value: [ "a" ], inverted: false, ignoreCase: false } ],
|
||
|
[ { type: "class", value: [ "a" ], inverted: false, ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "inverted case-sensitive", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
7 years ago
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [^a]", constsDetails(
|
||
|
[],
|
||
|
[ { value: [ "a" ], inverted: true, ignoreCase: false } ],
|
||
|
[ { type: "class", value: [ "a" ], inverted: true, ignoreCase: false } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
7 years ago
|
} );
|
||
7 years ago
|
|
||
7 years ago
|
} );
|
||
7 years ago
|
|
||
7 years ago
|
describe( "non-inverted case-insensitive", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
7 years ago
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]i", constsDetails(
|
||
|
[],
|
||
|
[ { value: [ "a" ], inverted: false, ignoreCase: true } ],
|
||
|
[ { type: "class", value: [ "a" ], inverted: false, ignoreCase: true } ],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
7 years ago
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "complex", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
7 years ago
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [ab-def-hij-l]", constsDetails(
|
||
|
[],
|
||
|
[
|
||
|
{
|
||
|
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
|
||
|
inverted: false,
|
||
|
ignoreCase: false
|
||
|
}
|
||
|
],
|
||
|
[
|
||
|
{
|
||
|
type: "class",
|
||
|
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
|
||
|
inverted: false,
|
||
|
ignoreCase: false
|
||
|
}
|
||
|
],
|
||
|
[]
|
||
|
) );
|
||
7 years ago
|
|
||
7 years ago
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=false|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "generates correct bytecode", function () {
|
||
7 years ago
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]", bytecodeDetails( [
|
||
7 years ago
|
20, 0, 2, 1, // MATCH_CLASS <0>
|
||
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "non-inverted case-sensitive", function () {
|
||
7 years ago
|
|
||
7 years ago
|
it( "defines correct constants", function () {
|
||
7 years ago
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]", constsDetails(
|
||
|
[], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], []
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
7 years ago
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "inverted case-sensitive", function () {
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [^a]", constsDetails(
|
||
|
[], [ { value: [ "a" ], inverted: true, ignoreCase: false } ], [], []
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "non-inverted case-insensitive", function () {
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [a]i", constsDetails(
|
||
|
[], [ { value: [ "a" ], inverted: false, ignoreCase: true } ], [], []
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "complex", function () {
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
7 years ago
|
expect( pass ).to.changeAST( "start = [ab-def-hij-l]", constsDetails(
|
||
|
[],
|
||
|
[
|
||
|
{
|
||
|
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
|
||
|
inverted: false,
|
||
|
ignoreCase: false
|
||
|
}
|
||
|
],
|
||
|
[],
|
||
|
[]
|
||
|
), {}, { reportFailures: false } );
|
||
7 years ago
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
describe( "for any", function () {
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=true|", function () {
|
||
7 years ago
|
|
||
7 years ago
|
const grammar = "start = .";
|
||
7 years ago
|
|
||
7 years ago
|
it( "generates bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
|
23, 0, // EXPECT <0>
|
||
|
17, 2, 1, // MATCH_ANY
|
||
7 years ago
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ) );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST(
|
||
|
grammar,
|
||
7 years ago
|
constsDetails( [], [], [ { type: "any" } ], [] )
|
||
7 years ago
|
);
|
||
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
7 years ago
|
describe( "when |reportFailures=false|", function () {
|
||
|
|
||
|
const grammar = "start = .";
|
||
7 years ago
|
|
||
7 years ago
|
it( "generates bytecode", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST( grammar, bytecodeDetails( [
|
||
|
17, 2, 1, // MATCH_ANY
|
||
7 years ago
|
21, 1, // * ACCEPT_N <1>
|
||
7 years ago
|
3 // * PUSH_FAILED
|
||
|
] ), {}, { reportFailures: false } );
|
||
|
|
||
|
} );
|
||
|
|
||
|
it( "defines correct constants", function () {
|
||
|
|
||
|
expect( pass ).to.changeAST(
|
||
|
grammar,
|
||
7 years ago
|
constsDetails( [], [], [], [] ),
|
||
7 years ago
|
{},
|
||
|
{ reportFailures: false }
|
||
|
);
|
||
|
|
||
|
} );
|
||
7 years ago
|
|
||
|
} );
|
||
|
|
||
|
} );
|
||
|
|
||
|
} );
|