GPM Templates: allow comments to start in any column, not just the first.

This commit is contained in:
Charles Haley 2025-07-08 12:34:10 +01:00
parent bb64863046
commit 3fc1bc2c2c
3 changed files with 5 additions and 3 deletions

View File

@ -293,7 +293,7 @@ Notes:
* In a logical context, any non-empty value is ``True``
* In a logical context, the empty value is ``False``
* Strings and numbers can be used interchangeably. For example, ``10`` and ``'10'`` are the same thing.
* Comments are lines starting with a '#' character. Comments beginning later in a line are not supported.
* Comments are lines starting with blanks or tabs then a '#' character.
**Operator precedence**

View File

@ -348,7 +348,9 @@ class TemplateHighlighter(QSyntaxHighlighter):
if not text:
pass
elif text[0] == '#':
elif re.match(r'[ \t]*#', text):
# Line with only a comment possibly preceded with spaces or tabs
# This works in both GPM and python
self.setFormat(0, textLength, self.Formats['comment'])
return

View File

@ -1715,7 +1715,7 @@ class TemplateFormatter(string.Formatter):
(r'\w+', lambda x,t: (_Parser.LEX_ID, t)),
(r'".*?((?<!\\)")', lambda x,t: (_Parser.LEX_CONST, t[1:-1])),
(r'\'.*?((?<!\\)\')', lambda x,t: (_Parser.LEX_CONST, t[1:-1])),
(r'\n#.*?(?:(?=\n)|$)', lambda x,t: _Parser.LEX_NEWLINE),
(r'\n[ \t]*#.*?(?:(?=\n)|$)',lambda x,t: _Parser.LEX_NEWLINE),
(r'\s', lambda x,t: _Parser.LEX_NEWLINE if t == '\n' else None),
], flags=re.DOTALL)