Example #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'
Example #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'
Example #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'
Example #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'
Example #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'
Example #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'
Example #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'
Example #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'
Example #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)))
Example #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'
Example #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)))
Example #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'
Example #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')