Пример #1
0
def test_multirule():
  rule = """production: SYM1 SYM2
                  | SYM2 SYM2 SYM2"""

  parsed = parse(rule)

  assert len(parsed) == 1
  assert parsed[0].format(pure_ply = False) == 'production : SYM1 SYM2 | SYM2 SYM2 SYM2'
Пример #2
0
def test_multirule():
    rule = """production: SYM1 SYM2
                  | SYM2 SYM2 SYM2"""

    parsed = parse(rule)

    assert len(parsed) == 1
    assert parsed[0].format(
        pure_ply=False) == 'production : SYM1 SYM2 | SYM2 SYM2 SYM2'
Пример #3
0
def test_multiline_rule():
    rule = """ production: SYM1 SYM2
  SYM3 SYM4
  """

    parsed = parse(rule)

    assert len(parsed) == 1
    assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4'
Пример #4
0
def test_two_rules():
    rule = """ r1: SYM1 SYM2
  r2: SYM2 SYM3"""

    parsed = parse(rule)

    assert len(parsed) == 2
    assert parsed[0].format() == 'r1 : SYM1 SYM2'
    assert parsed[1].format() == 'r2 : SYM2 SYM3'
Пример #5
0
def test_multiline_rule():
  rule = """ production: SYM1 SYM2
  SYM3 SYM4
  """

  parsed = parse(rule)

  assert len(parsed) == 1
  assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4'
Пример #6
0
def test_two_rules():
  rule = """ r1: SYM1 SYM2
  r2: SYM2 SYM3"""

  parsed = parse(rule)

  assert len(parsed) == 2
  assert parsed[0].format() == 'r1 : SYM1 SYM2'
  assert parsed[1].format() == 'r2 : SYM2 SYM3'
Пример #7
0
def test_multiline_rule_with_another_rule():
    rule = """ production: SYM1 SYM2
  SYM3 SYM4
  production2: S1 S2
  """

    parsed = parse(rule)

    assert len(parsed) == 2
    assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4'
    assert parsed[1].format() == 'production2 : S1 S2'
Пример #8
0
def test_multiline_rule_with_another_rule():
  rule = """ production: SYM1 SYM2
  SYM3 SYM4
  production2: S1 S2
  """

  parsed = parse(rule)

  assert len(parsed) == 2
  assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4'
  assert parsed[1].format() == 'production2 : S1 S2'
Пример #9
0
def assert_expand(rule, result):
    assert_eq_list(expand_optionals(rule), result)
    assert_eq_list(expand_optionals(rule, format=False),
                   parse('\n'.join(result)))
Пример #10
0
def test_printing():
    rule = parse('r: w1 (w1 {w2:name})?')[0]
    assert rule.format(pure_ply=False) == 'r : w1 (w1 {w2:name})?'
    assert rule.format(pure_ply=True) == 'r : w1 w1 w2'
    assert rule.format() == 'r : w1 w1 w2'
Пример #11
0
def assert_expand(rule, result):
  assert_eq_list(expand_optionals(rule), result)
  assert_eq_list(expand_optionals(rule, format = False), parse('\n'.join(result)))
Пример #12
0
def test_printing():
  rule = parse('r: w1 (w1 {w2:name})?')[0]
  assert rule.format(pure_ply = False)  == 'r : w1 (w1 {w2:name})?'
  assert rule.format(pure_ply = True) == 'r : w1 w1 w2'
  assert rule.format() == 'r : w1 w1 w2'
Пример #13
0
def test_printing():
  rule = parse('r: w1 (w1 {w2:name})?')[0]
  assert_eq(str(rule), 'r: w1 (w1 {w2:name})?')
  assert_eq(rule.format(), 'r : w1 w1 w2')