Skip to content

Commit

Permalink
yacc: unquote single characters
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Szakacs <attila.szakacs@oneidentity.com>
  • Loading branch information
alltilla committed Jun 3, 2022
1 parent 89fcd50 commit 7442354
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions neologism/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ def __yacc2xml(yacc_file_path: str, custom_path: str = None):
return xml_file


def __unescape(keyword: str) -> str:
if len(keyword) == 3 and keyword[0] == "'" and keyword[-1] == "'":
return keyword.strip("'")
return keyword


def __xml2rules(xml_file):
rules = set()

root = xml_parser.parse(xml_file.name).getroot()
for rule in root.iter("rule"):
lhs = rule.find("lhs").text
rhs = [symbol.text for symbol in rule.find("rhs") if symbol.tag != "empty"]
lhs = __unescape(rule.find("lhs").text)
rhs = [__unescape(symbol.text) for symbol in rule.find("rhs") if symbol.tag != "empty"]
rules.add(Rule(lhs, rhs))

return rules
Expand Down
2 changes: 1 addition & 1 deletion tests/test_yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_parse_yacc(yacc_file):
Rule("start", ("test",)),
Rule("test", ("test1", "test1next", "test1next")),
Rule("test", ("test2", "test2next", "test")),
Rule("test", ("KW_TEST", "'('", "test_opts", "')'")),
Rule("test", ("KW_TEST", "(", "test_opts", ")")),
Rule("test", ()),
Rule("test_opts", ("number",)),
Rule("test_opts", ("string",)),
Expand Down

0 comments on commit 7442354

Please sign in to comment.