From a5f26e727b0e5834a18dd7068d311feaa58488a0 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Mon, 14 Jan 2019 13:51:30 +1100 Subject: [PATCH] Fix minor booboos in C concatenated strings and scan_to_l.py macro text removal --- ast.py | 11 +++++++++-- scan_to_l.py | 28 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ast.py b/ast.py index b54e4fd..bcd537e 100644 --- a/ast.py +++ b/ast.py @@ -3477,8 +3477,15 @@ class AST(element.Element): return 'ast.AST.ExpressionStringLiteral({0:s})'.format(', '.join(params)) # GENERATE END def translate_expression(self, context, precedence): - return '\'{0:s}\''.format( - element.get_text(self[0], 0).replace('\\"', '"').replace('\'', '\\\'') + return ' '.join( + [ + '\'{0:s}\''.format( + element.get_text(i, 0). + replace('\\"', '"'). + replace('\'', '\\\'') + ) + for i in self + ] ) class ExpressionSubtract(ExpressionBinary): diff --git a/scan_to_l.py b/scan_to_l.py index 8389968..be21b01 100755 --- a/scan_to_l.py +++ b/scan_to_l.py @@ -72,40 +72,40 @@ text = element.to_text(root) # see tests/scan.l text = text.replace(r'{WS}[[:blank:]]+', '{WS}') -text = text.replace(r'{WS}([[:blank:]]+)', '{WS}') +text = text.replace(r'{WS}(?:[[:blank:]]+)', '{WS}') text = text.replace(r'{OPTWS}[[:blank:]]*', '{OPTWS}') -text = text.replace(r'{OPTWS}([[:blank:]]*)', '{OPTWS}') +text = text.replace(r'{OPTWS}(?:[[:blank:]]*)', '{OPTWS}') text = text.replace(r'{NOT_WS}[^[:blank:]\r\n]', '{NOT_WS}') -text = text.replace(r'{NOT_WS}([^[:blank:]\r\n])', '{NOT_WS}') +text = text.replace(r'{NOT_WS}(?:[^[:blank:]\r\n])', '{NOT_WS}') text = text.replace(r'{NL}\r?\n', '{NL}') -text = text.replace(r'{NL}(\r?\n)', '{NL}') +text = text.replace(r'{NL}(?:\r?\n)', '{NL}') text = text.replace(r'{NAME}([[:alpha:]_][[:alnum:]_-]*)', '{NAME}') -text = text.replace(r'{NAME}(([[:alpha:]_][[:alnum:]_-]*))', '{NAME}') +text = text.replace(r'{NAME}(?:([[:alpha:]_][[:alnum:]_-]*))', '{NAME}') text = text.replace(r'{NOT_NAME}[^[:alpha:]_*\n]+', '{NOT_NAME}') -text = text.replace(r'{NOT_NAME}([^[:alpha:]_*\n]+)', '{NOT_NAME}') +text = text.replace(r'{NOT_NAME}(?:[^[:alpha:]_*\n]+)', '{NOT_NAME}') text = text.replace(r'{SCNAME}{NAME}', '{SCNAME}') -text = text.replace(r'{SCNAME}({NAME})', '{SCNAME}') +text = text.replace(r'{SCNAME}(?:{NAME})', '{SCNAME}') text = text.replace(r'{ESCSEQ}(\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2}))', '{ESCSEQ}') -text = text.replace(r'{ESCSEQ}((\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2})))', '{ESCSEQ}') +text = text.replace(r'{ESCSEQ}(?:(\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2})))', '{ESCSEQ}') text = text.replace(r'{FIRST_CCL_CHAR}([^\\\n]|{ESCSEQ})', '{FIRST_CCL_CHAR}') -text = text.replace(r'{FIRST_CCL_CHAR}(([^\\\n]|{ESCSEQ}))', '{FIRST_CCL_CHAR}') +text = text.replace(r'{FIRST_CCL_CHAR}(?:([^\\\n]|{ESCSEQ}))', '{FIRST_CCL_CHAR}') text = text.replace(r'{CCL_CHAR}([^\\\n\]]|{ESCSEQ})', '{CCL_CHAR}') -text = text.replace(r'{CCL_CHAR}(([^\\\n\]]|{ESCSEQ}))', '{CCL_CHAR}') +text = text.replace(r'{CCL_CHAR}(?:([^\\\n\]]|{ESCSEQ}))', '{CCL_CHAR}') text = text.replace(r'{CCL_EXPR}("[:"^?[[:alpha:]]+":]")', '{CCL_EXPR}') -text = text.replace(r'{CCL_EXPR}(("[:"^?[[:alpha:]]+":]"))', '{CCL_EXPR}') +text = text.replace(r'{CCL_EXPR}(?:("[:"^?[[:alpha:]]+":]"))', '{CCL_EXPR}') text = text.replace(r'{LEXOPT}[aceknopr]', '{LEXOPT}') -text = text.replace(r'{LEXOPT}([aceknopr])', '{LEXOPT}') +text = text.replace(r'{LEXOPT}(?:[aceknopr])', '{LEXOPT}') text = text.replace(r'{M4QSTART}"[""["', '{M4QSTART}') -text = text.replace(r'{M4QSTART}("[""[")', '{M4QSTART}') +text = text.replace(r'{M4QSTART}(?:"[""[")', '{M4QSTART}') text = text.replace(r'{M4QEND}"]""]"', '{M4QEND}') -text = text.replace(r'{M4QEND}("]""]")', '{M4QEND}') +text = text.replace(r'{M4QEND}(?:"]""]")', '{M4QEND}') # we can only calculate column numbering once all substitutions done i = 0 -- 2.34.1