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
|
@ -212,8 +212,7 @@ def namespace(ctx: CompletionContext):
|
||||||
language.BracketedTypeName,
|
language.BracketedTypeName,
|
||||||
],
|
],
|
||||||
matches=[
|
matches=[
|
||||||
[(TokenType.IDENT, None), (TokenType.OP, "."), (TokenType.IDENT, None)],
|
[TokenType.IDENT, "."],
|
||||||
[(TokenType.IDENT, None), (TokenType.OP, ".")],
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def object_completer(ctx: CompletionContext):
|
def object_completer(ctx: CompletionContext):
|
||||||
|
@ -301,9 +300,9 @@ def property_completer(ctx: CompletionContext):
|
||||||
@completer(
|
@completer(
|
||||||
applies_in=[language.Property, language.A11yProperty],
|
applies_in=[language.Property, language.A11yProperty],
|
||||||
matches=[
|
matches=[
|
||||||
[(TokenType.IDENT, None), (TokenType.OP, ":")],
|
[TokenType.IDENT, ":"],
|
||||||
[(TokenType.PUNCTUATION, ",")],
|
[","],
|
||||||
[(TokenType.PUNCTUATION, "[")],
|
["["],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def prop_value_completer(ctx: CompletionContext):
|
def prop_value_completer(ctx: CompletionContext):
|
||||||
|
@ -424,7 +423,7 @@ def template_completer(_ctx: CompletionContext):
|
||||||
|
|
||||||
@completer(
|
@completer(
|
||||||
applies_in=[language.ObjectContent, language.ChildType],
|
applies_in=[language.ObjectContent, language.ChildType],
|
||||||
matches=[[(TokenType.PUNCTUATION, "[")]],
|
matches=[["["]],
|
||||||
applies_in_subclass=[("Gtk", "Dialog"), ("Gtk", "InfoBar")],
|
applies_in_subclass=[("Gtk", "Dialog"), ("Gtk", "InfoBar")],
|
||||||
)
|
)
|
||||||
def response_id_completer(ctx: CompletionContext):
|
def response_id_completer(ctx: CompletionContext):
|
||||||
|
@ -438,7 +437,7 @@ def response_id_completer(ctx: CompletionContext):
|
||||||
|
|
||||||
@completer(
|
@completer(
|
||||||
[language.ChildAnnotation, language.ExtResponse],
|
[language.ChildAnnotation, language.ExtResponse],
|
||||||
[[(TokenType.IDENT, "action"), (TokenType.IDENT, "response"), (TokenType.OP, "=")]],
|
[["action", "response", "="]],
|
||||||
)
|
)
|
||||||
def complete_response_id(ctx: CompletionContext):
|
def complete_response_id(ctx: CompletionContext):
|
||||||
gir = ctx.ast_node.root.gir
|
gir = ctx.ast_node.root.gir
|
||||||
|
@ -457,16 +456,16 @@ def complete_response_id(ctx: CompletionContext):
|
||||||
[language.ChildAnnotation, language.ExtResponse],
|
[language.ChildAnnotation, language.ExtResponse],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
(TokenType.IDENT, "action"),
|
"action",
|
||||||
(TokenType.IDENT, "response"),
|
"response",
|
||||||
(TokenType.OP, "="),
|
"=",
|
||||||
(TokenType.IDENT, None),
|
TokenType.IDENT,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
(TokenType.IDENT, "action"),
|
"action",
|
||||||
(TokenType.IDENT, "response"),
|
"response",
|
||||||
(TokenType.OP, "="),
|
"=",
|
||||||
(TokenType.NUMBER, None),
|
TokenType.NUMBER,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -53,11 +53,11 @@ class CompletionContext:
|
||||||
|
|
||||||
|
|
||||||
new_statement_patterns = [
|
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):
|
if len(pattern) <= len(prev_tokens):
|
||||||
for i in range(0, len(pattern)):
|
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)]
|
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
|
value is not None and str(token) != value
|
||||||
):
|
):
|
||||||
break
|
break
|
||||||
|
|
|
@ -251,7 +251,7 @@ def decompile_signal(
|
||||||
|
|
||||||
@completer(
|
@completer(
|
||||||
[Signal],
|
[Signal],
|
||||||
[[(TokenType.PUNCTUATION, "(")]],
|
[["("]],
|
||||||
)
|
)
|
||||||
def signal_object_completer(ctx: CompletionContext):
|
def signal_object_completer(ctx: CompletionContext):
|
||||||
yield from get_object_id_completions(ctx)
|
yield from get_object_id_completions(ctx)
|
||||||
|
|
|
@ -153,7 +153,7 @@ def complete_mark(_ctx: CompletionContext):
|
||||||
|
|
||||||
@completer(
|
@completer(
|
||||||
applies_in=[ExtScaleMark],
|
applies_in=[ExtScaleMark],
|
||||||
matches=[[(TokenType.NUMBER, None), (TokenType.PUNCTUATION, ",")]],
|
matches=[[TokenType.NUMBER, ","]],
|
||||||
)
|
)
|
||||||
def complete_mark_position(ctx: CompletionContext):
|
def complete_mark_position(ctx: CompletionContext):
|
||||||
gir = ctx.ast_node.root.gir
|
gir = ctx.ast_node.root.gir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue