Exemplo n.º 1
0
),
R('RULE p:b <= a b {c, d} e _',
  ['a','b','c','e','p:@'],
  ['a','b','d','e','p:@']
),
R('''
SUBSET V a e i o u
RULE p:b <= V _ +:0
''',
  ['V','p:@',('+','0')]
),
R('RULE c:t <= x (z [ f | :g | h: ]) _',
  ['x','z','f','c:@'],
  ['x','z','@:g','c:@'],
  ['x','z','h:@','c:@'],
  ['x','c:@'],
),
]


def rules_parser_driver(data):
    klexer = KgenLexer()
    mockAST = MockAST()
    output = StringIO()
    kparser = KgenParser(klexer, output, mockAST)
    kparser.parse(data)
    return mockAST.rhs


RulesParserTestCase = generate_class('RulesParserTestCase', rules_parser_driver, data_list)
Exemplo n.º 2
0
R('test_pairs',
'''
SUBSET C b c d
!; default correspondence
PAIRS b c d +
      b c d 0
''',
NODE_TYPE_NEWLINE, NODE_TYPE_SUBSET, NODE_TYPE_KIMMOCOMMENT, NODE_TYPE_PAIR),

R('test_rules',
'''
!;only rule
RULE p:b => _ +:0 m
!;always rule
RULE p:b <= _ +:0 m
''',
NODE_TYPE_NEWLINE, NODE_TYPE_KIMMOCOMMENT, NODE_TYPE_RULE, NODE_TYPE_KIMMOCOMMENT, NODE_TYPE_RULE),

]

def ParseTree_driver(data):
    klexer = KgenLexer()
    ptree = ParseTree()
    output = StringIO()
    kparser = KgenParser(klexer, output, ptree)
    kparser.parse(data, ptree)
    return [node.type for node in ptree]


ParseTreeTestCase = generate_class('ParseTreeTestCase', ParseTree_driver, data_list)
Exemplo n.º 3
0
    R(
        "test_only_rule_case12",
        "RULE    s:z /<= v _ v",
        """
   v s @
   v z @
  -------
1: 2 1 1
2: 2 3 1
3: 0 1 1
""",
    ),
]


def buildtable_driver(data):
    print data

    klexer = KgenLexer()
    mockAST = MockAST()
    output = StringIO()
    kparser = KgenParser(klexer, output, mockAST)

    kparser.parse(data, mockAST)
    columns, table = build_kgen_table(mockAST.rules[0][2], mockAST.rules[0][3])
    print "%s\n%s" % (columns, table)
    return "\n%s\n%s" % (columns, table)


BuildTableTestCase = generate_class("BuildTableTestCase", buildtable_driver, data_list)