parser: allow whitespaces and comments in cont_eol

FIXME: another approach would be to consider cont_eol as comment (i.e.
add backslash and whitespaces to the comment regex). In both cases it
works until we want to parse comments separately.

TODO?: handle eol_cont inside a string (to split long string without
breaking lines). Probably a bad idea and better to simply join a
multiline string.
pull/12152/head
Charles Brunet 2 years ago
parent d3a26d158e
commit 14e35b63c0
  1. 2
      mesonbuild/mparser.py
  2. 12
      test cases/unit/118 rewrite/meson.build

@ -121,7 +121,7 @@ class Lexer:
('fstring', re.compile(r"f'([^'\\]|(\\.))*'")),
('id', re.compile('[_a-zA-Z][_0-9a-zA-Z]*')),
('number', re.compile(r'0[bB][01]+|0[oO][0-7]+|0[xX][0-9a-fA-F]+|0|[1-9]\d*')),
('eol_cont', re.compile(r'\\\n')),
('eol_cont', re.compile(r'\\[ \t]*(#.*)?\n')),
('eol', re.compile(r'\n')),
('multiline_string', re.compile(r"'''(.|\n)*?'''", re.M)),
('comment', re.compile(r'#.*')),

@ -173,12 +173,12 @@ no_string_escapes = '''\\\'\a\b\f\n\r\t\v\046\x26\u2D4d\U00002d4d\N{GREEK CAPITA
# cont_string = 'blablabla\
# blablabla'
# FIXME: is it supposed to work? (cont_eol with whitespace and comments after)
# if a \ # comment in cont 1
# and b \ # comment in cont 2
# or c # comment in cont 3
# message('ok')
# endif
# cont_eol with whitespace and comments after
if a \ # comment in cont 1
and b \ # comment in cont 2
or c # comment in cont 3
message('ok')
endif
if a \
or b

Loading…
Cancel
Save