parsing - Getting tokens based on length and position inside input -
on input have stream of characters not separated delimiter, this:
input = "150001"
i want make parser(using jison), tokenize based on position , length, should tokens:
15 - system id (first 2 numbers) 0001 - order num (4 numbers after)
can give me advice how can accomplish this, tried add tokens this:
%lex %% [0-9]{2} return "system_id" [0-9]{4} return "order_num" \lex %%
but expected not working :)
is there way parse kind of inputs, parse length of characters ?
you can make simple parser using state-declarations, , assigning state each of rules. referring jison's documentation, change (noting lexer still incomplete because nothing identifier or "="):
%lex %s system_id order_num %% /* more logic needed accept identifier, "=", each own state, , beginning "system_id" state. */ <system_id>[0-9]{2} this.begin("order_num"); return "system_id" <order_num>[0-9]{4} this.begin('initial'); return "order_num"
\lex %%
Comments
Post a Comment