From a2b38472dcf4f0c9d34b664f94978cdb2b129b02 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 24 Jan 2019 23:03:50 +1100 Subject: [PATCH] Minor adjustment since recent change to bootstrap_bison.git markup generation --- ast.py | 62 +++++++++++++++++++++++++------------------------- p.sh | 1 + q.sh | 1 + y_to_python.py | 14 +++++++++++- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/ast.py b/ast.py index 7a362bb..6ec5a52 100644 --- a/ast.py +++ b/ast.py @@ -2771,37 +2771,6 @@ class AST(element.Element): text = '0o' + text[1:] return text - class Identifier(element.Element): - # GENERATE ELEMENT() BEGIN - def __init__( - self, - tag = 'AST_Identifier', - attrib = {}, - text = '', - children = [] - ): - element.Element.__init__( - self, - tag, - attrib, - text, - children - ) - def copy(self, factory = None): - result = element.Element.copy( - self, - Identifier if factory is None else factory - ) - return result - def __repr__(self): - params = [] - self.repr_serialize(params) - return 'ast.AST.Identifier({0:s})'.format(', '.join(params)) - # GENERATE END - def translate_identifier(self, context): - text = element.get_text(self, 0) - return context.translate_identifier.get(text, text) - class ExpressionLeftShiftAssignment(ExpressionBinary): # GENERATE ELEMENT() BEGIN def __init__( @@ -3828,6 +3797,37 @@ class AST(element.Element): return 'ast.AST.GenericSelection({0:s})'.format(', '.join(params)) # GENERATE END + class Identifier(element.Element): + # GENERATE ELEMENT() BEGIN + def __init__( + self, + tag = 'AST_Identifier', + attrib = {}, + text = '', + children = [] + ): + element.Element.__init__( + self, + tag, + attrib, + text, + children + ) + def copy(self, factory = None): + result = element.Element.copy( + self, + Identifier if factory is None else factory + ) + return result + def __repr__(self): + params = [] + self.repr_serialize(params) + return 'ast.AST.Identifier({0:s})'.format(', '.join(params)) + # GENERATE END + def translate_identifier(self, context): + text = element.get_text(self, 0) + return context.translate_identifier.get(text, text) + class IdentifierEmpty(element.Element): # GENERATE ELEMENT() BEGIN def __init__( diff --git a/p.sh b/p.sh index 556c010..3c4efe0 100755 --- a/p.sh +++ b/p.sh @@ -1,4 +1,5 @@ #!/bin/sh ../bootstrap_flex.git/src/flex -o /dev/null tests/scan-gram.l 2>tests/scan-gram.l.xml +rm lex.yy.c ./l_to_python.py -I tests/bison_h tests/scan-gram.l.new.xml ./scan-gram_to_l.py tests/scan-gram.l.new diff --git a/q.sh b/q.sh index c21175e..61a3803 100755 --- a/q.sh +++ b/q.sh @@ -1,4 +1,5 @@ #!/bin/sh ../bootstrap_flex.git/src/flex -o /dev/null tests/scan-code.l 2>tests/scan-code.l.xml +rm lex.yy.c ./l_to_python.py -I tests/bison_h tests/scan-code.l.new.xml ./scan-code_to_l.py tests/scan-code.l.new diff --git a/y_to_python.py b/y_to_python.py index 78d5494..8f93615 100755 --- a/y_to_python.py +++ b/y_to_python.py @@ -100,7 +100,19 @@ with open('a.c', 'w') as fout: 0, element.get_text(i, 0).lstrip() ) - for j in range(1, len(i) + 1): + # deal with ... : + assert i[0].tag == 'AST_SymbolRef' + element.set_text( + i[0], + 1, + '\n ' + element.get_text(i[0], 1).strip() + ) + element.set_text( + i, + 1, + element.get_text(i, 1).strip() + ) + for j in range(2, len(i) + 1): element.set_text( i, j, -- 2.34.1