@@ -354,7 +354,7 @@ module.exports = function(ast) {
354354 }
355355
356356 function buildSimplePredicate ( expression , negative , context ) {
357- const match = expression . match | 0 ;
357+ const match = expression . match || 0 ;
358358
359359 return buildSequence (
360360 [ op . PUSH_CURR_POS ] ,
@@ -392,7 +392,7 @@ module.exports = function(ast) {
392392 [ op . UPDATE_SAVED_POS ] ,
393393 buildCall ( functionIndex , 0 , context . env , context . sp ) ,
394394 buildCondition (
395- node . match | 0 ,
395+ node . match || 0 ,
396396 [ op . IF ] ,
397397 buildSequence (
398398 [ op . POP ] ,
@@ -525,7 +525,7 @@ module.exports = function(ast) {
525525 action : null ,
526526 } ) ,
527527 buildCondition (
528- delimiterNode . match | 0 ,
528+ delimiterNode . match || 0 ,
529529 [ op . IF_NOT_ERROR ] , // if (item !== peg_FAILED) {
530530 buildSequence (
531531 [ op . POP ] , // stack:[ pos ]
@@ -572,10 +572,10 @@ module.exports = function(ast) {
572572 } ,
573573
574574 named ( node , context ) {
575- const match = node . match | 0 ;
575+ const match = node . match || 0 ;
576576 // Expectation not required if node always fail
577577 const nameIndex = ( match === NEVER_MATCH )
578- ? null
578+ ? - 1
579579 : addExpectedConst ( { type : "rule" , value : node . name } ) ;
580580
581581 // The code generated below is slightly suboptimal because |FAIL| pushes
@@ -592,7 +592,7 @@ module.exports = function(ast) {
592592
593593 choice ( node , context ) {
594594 function buildAlternativesCode ( alternatives , context ) {
595- const match = alternatives [ 0 ] . match | 0 ;
595+ const match = alternatives [ 0 ] . match || 0 ;
596596 const first = generate ( alternatives [ 0 ] , {
597597 sp : context . sp ,
598598 env : cloneEnv ( context . env ) ,
@@ -637,11 +637,11 @@ module.exports = function(ast) {
637637 env,
638638 action : node ,
639639 } ) ;
640- const match = node . expression . match | 0 ;
640+ const match = node . expression . match || 0 ;
641641 // Function only required if expression can match
642642 const functionIndex = ( emitCall && match !== NEVER_MATCH )
643643 ? addFunctionConst ( false , Object . keys ( env ) , node )
644- : null ;
644+ : - 1 ;
645645
646646 return emitCall
647647 ? buildSequence (
@@ -674,7 +674,7 @@ module.exports = function(ast) {
674674 action : null ,
675675 } ) ,
676676 buildCondition (
677- elements [ 0 ] . match | 0 ,
677+ elements [ 0 ] . match || 0 ,
678678 [ op . IF_NOT_ERROR ] ,
679679 buildElementsCode ( elements . slice ( 1 ) , {
680680 sp : context . sp + 1 ,
@@ -764,7 +764,7 @@ module.exports = function(ast) {
764764 action : null ,
765765 } ) ,
766766 buildCondition (
767- node . match | 0 ,
767+ node . match || 0 ,
768768 [ op . IF_NOT_ERROR ] ,
769769 buildSequence ( [ op . POP ] , [ op . TEXT ] ) ,
770770 [ op . NIP ]
@@ -791,7 +791,7 @@ module.exports = function(ast) {
791791 // Check expression match, not the node match
792792 // If expression always match, no need to replace FAILED to NULL,
793793 // because FAILED will never appeared
794- - ( node . expression . match | 0 ) ,
794+ - ( node . expression . match || 0 ) ,
795795 [ op . IF_ERROR ] ,
796796 buildSequence ( [ op . POP ] , [ op . PUSH_NULL ] ) ,
797797 [ ]
@@ -826,7 +826,7 @@ module.exports = function(ast) {
826826 expressionCode ,
827827 buildCondition (
828828 // Condition depends on the expression match, not the node match
829- node . expression . match | 0 ,
829+ node . expression . match || 0 ,
830830 [ op . IF_NOT_ERROR ] ,
831831 buildSequence ( buildAppendLoop ( expressionCode ) , [ op . POP ] ) ,
832832 buildSequence ( [ op . POP ] , [ op . POP ] , [ op . PUSH_FAILED ] )
@@ -874,7 +874,7 @@ module.exports = function(ast) {
874874 : firstExpressionCode ;
875875 const bodyCode = buildRangeBody (
876876 node . delimiter ,
877- node . expression . match | 0 ,
877+ node . expression . match || 0 ,
878878 expressionCode ,
879879 context ,
880880 offset
@@ -929,7 +929,7 @@ module.exports = function(ast) {
929929
930930 literal ( node ) {
931931 if ( node . value . length > 0 ) {
932- const match = node . match | 0 ;
932+ const match = node . match || 0 ;
933933 // String only required if condition is generated or string is
934934 // case-sensitive and node always match
935935 const needConst = ( match === SOMETIMES_MATCH )
@@ -940,15 +940,15 @@ module.exports = function(ast) {
940940 ? node . value . toLowerCase ( )
941941 : node . value
942942 )
943- : null ;
943+ : - 1 ;
944944 // Expectation not required if node always match
945945 const expectedIndex = ( match !== ALWAYS_MATCH )
946946 ? addExpectedConst ( {
947947 type : "literal" ,
948948 value : node . value ,
949949 ignoreCase : node . ignoreCase ,
950950 } )
951- : null ;
951+ : - 1 ;
952952
953953 // For case-sensitive strings the value must match the beginning of the
954954 // remaining input exactly. As a result, we can use |ACCEPT_STRING| and
@@ -969,11 +969,11 @@ module.exports = function(ast) {
969969 } ,
970970
971971 class ( node ) {
972- const match = node . match | 0 ;
972+ const match = node . match || 0 ;
973973 // Character class constant only required if condition is generated
974974 const classIndex = ( match === SOMETIMES_MATCH )
975975 ? addClassConst ( node )
976- : null ;
976+ : - 1 ;
977977 // Expectation not required if node always match
978978 const expectedIndex = ( match !== ALWAYS_MATCH )
979979 ? addExpectedConst ( {
@@ -982,7 +982,7 @@ module.exports = function(ast) {
982982 inverted : node . inverted ,
983983 ignoreCase : node . ignoreCase ,
984984 } )
985- : null ;
985+ : - 1 ;
986986
987987 return buildCondition (
988988 match ,
@@ -993,13 +993,13 @@ module.exports = function(ast) {
993993 } ,
994994
995995 any ( node ) {
996- const match = node . match | 0 ;
996+ const match = node . match || 0 ;
997997 // Expectation not required if node always match
998998 const expectedIndex = ( match !== ALWAYS_MATCH )
999999 ? addExpectedConst ( {
10001000 type : "any" ,
10011001 } )
1002- : null ;
1002+ : - 1 ;
10031003
10041004 return buildCondition (
10051005 match ,
0 commit comments