yargy icon indicating copy to clipboard operation
yargy copied to clipboard

A (,? B)? (,? C)? не метчит A C

Open kuk opened this issue 6 years ago • 0 comments

A = rule('a')
B = rule('b')
C = rule('c')
SEP = eq(',')
MAYBE_SEP = SEP.optional()

RULE = rule(
    A,
    rule(
        MAYBE_SEP,
        B
    ).optional(),
    rule(
        MAYBE_SEP,
        C
    ).optional()
)
parser = Parser(RULE)
line = 'a c'
list(parser.match(line))
[]


RULE.normalized.as_bnf
R0 -> 'a' R1 R2
R1 -> R3 'b' | R4
R2 -> R3 'c' | R5
R3 -> ',' | R6
R4 -> e
R5 -> e
R6 -> e


parser.chart(line)
0 None
----------------
[0:0] R0 -> $ 'a' R1 R2

1 Token('a', (0, 1), [Form('a', {'LATN'})])
----------------
[0:1] R0 -> 'a' $ R1 R2
[1:1] R0 -> $ 'a' R1 R2
[1:1] R1 -> $ R3 'b'
[1:1] R1 -> $ R4
[1:1] R3 -> $ ','
[1:1] R3 -> $ R6
[1:1] R4 -> $
[1:1] R6 -> $
[1:1] R1 -> R4 $
[1:1] R3 -> R6 $
[0:1] R0 -> 'a' R1 $ R2
[1:1] R1 -> R3 $ 'b'
[1:1] R2 -> $ R3 'c'
[1:1] R2 -> $ R5
[1:1] R5 -> $
[1:1] R2 -> R5 $
[0:1] R0 -> 'a' R1 R2 $

2 Token('c', (2, 3), [Form('c', {'LATN'})])
----------------
[2:2] R0 -> $ 'a' R1 R2

kuk avatar Sep 14 '17 10:09 kuk