1

Trying to make a parser with grako to parse something like

tag1: line1
line 2 ... 
tag2: line1 
line2
... 

such that whitespaces before tag1 should be ignored; but tags should start at new line.

Small ebnf (x.ebnf)

START = DATA $;

DATA = piece:{PIECE}+ ;

PIECE = x | y;

sep = ":";

xtag = /^\s*x[^:]*/ sep;
ytag = /^\s*y[^:]*/ sep;

x = xtag val:userinput ;
y = ytag val:userinput ;

userfirstinput = /.*/;
userinput = firstline+:userfirstinput lines:{line}*;
line  = !PIECE /.*/;

input (test):

  x: First
y: liney
liney2 x: is not x

start:

python3 xparser.py -t test START

Error:

grako.exceptions.FailedParse: test.event(1:1) no available options :
  x: First

^
PIECE
DATA
START

Question: Why?! I put ^\s*x , why it does not match?

Thanks for any hint!

4

0 回答 0