Fix minor booboos in C concatenated strings and scan_to_l.py macro text removal
authorNick Downing <nick@ndcode.org>
Mon, 14 Jan 2019 02:51:30 +0000 (13:51 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 14 Jan 2019 02:51:55 +0000 (13:51 +1100)
ast.py
scan_to_l.py

diff --git a/ast.py b/ast.py
index b54e4fd..bcd537e 100644 (file)
--- 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):
index 8389968..be21b01 100755 (executable)
@@ -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