mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-07-07 01:29:26 -04:00
completions: Simplify token matching code
This commit is contained in:
parent
c7a61d2227
commit
610d9c85a5
4 changed files with 27 additions and 24 deletions
|
@ -53,11 +53,11 @@ class CompletionContext:
|
|||
|
||||
|
||||
new_statement_patterns = [
|
||||
[(TokenType.PUNCTUATION, "{")],
|
||||
[(TokenType.PUNCTUATION, "}")],
|
||||
[(TokenType.PUNCTUATION, "]")],
|
||||
[(TokenType.PUNCTUATION, ";")],
|
||||
[(TokenType.OP, "<")],
|
||||
["{"],
|
||||
["}"],
|
||||
["]"],
|
||||
[";"],
|
||||
["<"],
|
||||
]
|
||||
|
||||
|
||||
|
@ -101,9 +101,13 @@ def completer(applies_in: T.List, matches: T.List = [], applies_in_subclass=None
|
|||
|
||||
if len(pattern) <= len(prev_tokens):
|
||||
for i in range(0, len(pattern)):
|
||||
type, value = pattern[i]
|
||||
if isinstance(pattern[i], str):
|
||||
type, value = None, pattern[i]
|
||||
elif isinstance(pattern[i], TokenType):
|
||||
type, value = pattern[i], None
|
||||
|
||||
token = prev_tokens[i - len(pattern)]
|
||||
if token.type != type or (
|
||||
if (type is not None and token.type != type) or (
|
||||
value is not None and str(token) != value
|
||||
):
|
||||
break
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue