In JISON, is there a way to parse a string for an individual production? For instance, this primitive parser defines a master expressions
in terms of several productions such as ary
.
Right now this returns a function that can parse expressions
:
var parser = jison.Parser(bnf);
var str = "A(1-3,5)&B(1,2,3)"
var result = parser.parse(str) // this works
But i'd like to also parse strings matching individual productions like ary
,
var str = "1-3,5"
var result = parser.ary.parse(str) /// this does not work
Here's an example grammar with some of the Javascript removed:
%start expressions
/* language grammar */
%%
expressions: e EOF {...}
;
assign: ID LPAR ary RPAR
;
predicate: COUNT LPAR elist constraint RPAR { ... }
;
e : TN { $$ = {}; }
| predicate { $$ = $1; }
| e '&' e { $$ = _.merge({},$1,$3); }
| e '!' e { $$ = { "$or": [$1,$3]}; }
| '?' e { $$ = { "$not": $2 }; }
| '{' e '}' { $$ = $2; }
| assign { $$ = $1; }
;
/* Seguir desde aca. Esta es la unica expr que sigue jodiendo... */
elist: elist SEMI e { ... }
| e { ... }
;
constraint: SEMI comparator val { ... }
| SEMI val {... }
;
ary: val { $$ = [$1]; }
| ary "," val
;
val: NUMBER { $$ = +$1; }
| '-' NUMBER { $$ = - (+$2); }
| ID { $$ = $1; }
| STRING { $$ = $1; }
| NUMBER '-' NUMBER { $$ = _.range(+$1, +$3+1); }
| '(' ary ')' { $$ = $1; }
;
comparator: '$eq'
| '$lte'
| '$gte'
| '$gt'
| '$lt' { $$ = $1; }
;