dtlib: handle GCC linemarkers

A GCC linemarker of the form:

  # 1 "filename" 2 3 4

or so is not currently being handled, because the current regular
expression assumes the "flags" values (the numbers after "filename")
are limited to a single value. Tweak the regular expression to allow
for up to 4 flags, which is what GCC documents it may emit:

https://gcc.gnu.org/onlinedocs/gcc-10.2.0/cpp/Preprocessor-Output.html

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-12-03 15:10:07 -08:00 committed by Anas Nashif
parent 4e783a363a
commit 7738977af4

View file

@ -1962,9 +1962,9 @@ def _init_tokens():
# _Token.val is based on the captured string.
token_spec = {
_T.INCLUDE: r'(/include/\s*"(?:[^\\"]|\\.)*")',
# #line directive
# #line directive or GCC linemarker
_T.LINE:
r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+)?',
r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+){0,4}',
_T.STRING: r'"((?:[^\\"]|\\.)*)"',
_T.DTS_V1: r"(/dts-v1/)",