From 417abe105c3d7bfa2c4753306cf03a9ab89d1f54 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 21 Apr 2013 16:47:20 +0300 Subject: Added multiline strings. --- mparser.py | 12 ++++++++++++ test cases/common/32 multiline string/meson.build | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 test cases/common/32 multiline string/meson.build diff --git a/mparser.py b/mparser.py index 8954a9f1d..821ec35b4 100644 --- a/mparser.py +++ b/mparser.py @@ -39,6 +39,7 @@ tokens = ['LPAREN', 'COMMA', 'DOT', 'STRING', + 'MULTILINE_STRING', 'INT', 'EOL_CONTINUE', 'EOL', @@ -66,6 +67,13 @@ def t_ATOM(t): t.type = reserved.get(t.value, 'ATOM') return t + +def t_MULTILINE_STRING(t): + r"'''(.|\n)*?'''" + t.value = t.value[3:-3] + t.lexer.lineno += t.value.count('\n') + return t + def t_STRING(t): "'[^']*'" t.value = t.value[1:-1] @@ -127,6 +135,10 @@ def p_expression_string(t): 'expression : STRING' t[0] = nodes.StringExpression(t[1], t.lineno(1)) +def p_expression_multiline_string(t): + 'expression : MULTILINE_STRING' + t[0] = nodes.StringExpression(t[1], t.lineno(1)) + def p_statement_assign(t): 'statement : expression ASSIGN statement' t[0] = nodes.Assignment(t[1], t[3], t[1].lineno()) diff --git a/test cases/common/32 multiline string/meson.build b/test cases/common/32 multiline string/meson.build new file mode 100644 index 000000000..d4a0278e6 --- /dev/null +++ b/test cases/common/32 multiline string/meson.build @@ -0,0 +1,9 @@ +project('multiline string', 'c') + +x = '''hello again''' +y = '''hello +again''' + +if x == y + error('Things are wrong.') +endif -- cgit v1.2.3