From fa39f9d6329a3ecad69a045d7df48475466e8ed6 Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Mon, 16 Mar 2020 12:13:18 +0100 Subject: [PATCH] [INTERNAL] [IMPORTANT] Stack management rework, please read below : `push` followed by `include` statements were not working as expected, due to unconsumed white-space characters. See . This patch implements one of the [sublimehq/Packages#757] advices, which is to use both a popping and pop-less versions of the same reusable context. See from @tajmone. Such "new" contexts will be annotated as `_expect-${POPLESS-CONTEXT-NAME}` in `Nftables`. It also fixes other usages of `force-pop`, that had ended up badly working. --- Nftables.sublime-syntax | 41 ++++++++++++++++++++-------------------- syntax_test_Nftables.nft | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Nftables.sublime-syntax b/Nftables.sublime-syntax index d1591a1..8178ba6 100644 --- a/Nftables.sublime-syntax +++ b/Nftables.sublime-syntax @@ -17,6 +17,7 @@ variables: integer: (?:[[:digit:]]+) hexadecimal: (?:(?:0x)[[:xdigit:]]+) + time_string: (?:(?:\d+[wdhms])+) identifier: (?:[[:alpha:]][[:alnum:]_]*) identifier_extended: (?:[[:alpha:]][[:alnum:]_\-]*) @@ -64,10 +65,6 @@ contexts: - include: variables - include: line-continuation - force-pop: - - match: '' - pop: true - comments: - match: (#) scope: punctuation.definition.comment.nftables @@ -141,12 +138,20 @@ contexts: pop: true time-string: - - match: \b((?:\d+[wdhms])+)\b + - match: \b({{time_string}})\b scope: string.unquoted.time-string.nftables + _expect-time-string: + - match: \b({{time_string}})\b + scope: string.unquoted.time-string.nftables + pop: true unquoted-string: - match: \b({{identifier_extended}})\b scope: string.unquoted.nftables + _expect-unquoted-string: + - match: \b({{identifier_extended}})\b + scope: string.unquoted.nftables + pop: true network-addresses: - match: ({{mac_address}}) @@ -182,6 +187,10 @@ contexts: # This context is not included in `numerics` because `signed-integer` supersedes it. - match: \b({{integer}})\b scope: constant.numeric.integer.nftables + _expect-integer: + - match: \b({{integer}})\b + scope: constant.numeric.integer.nftables + pop: true anonymous-set: - match: ({) @@ -193,9 +202,7 @@ contexts: # Elements in the set may have a `timeout` (death-date). - match: \b(timeout)\b scope: storage.type.set-element-timeout.nftables - push: - - include: time-string - - include: force-pop + push: _expect-time-string - include: verdict-statements - include: values @@ -333,9 +340,7 @@ contexts: set: - match: \b(handle|position)\b scope: keyword.other.handle.nftables - push: - - include: integer - - include: force-pop + push: _expect-integer - include: rule-definitions - include: statement-separators @@ -452,9 +457,7 @@ contexts: set: - match: \b(device)\b scope: storage.type.chain-device.nftables - push: - - include: unquoted-string - - include: force-pop + push: _expect-unquoted-string - match: \b(priority)\b scope: storage.type.chain-priority.nftables @@ -578,16 +581,14 @@ contexts: scope: entity.name.quota.nftables set: - include: integer + - match: \b(over|until)\b scope: constant.language.quota-mode.nftables - push: - - include: integer - - include: force-pop + push: _expect-integer - match: \b(used)\b scope: constant.language.quota-used.nftables - push: - - include: integer - - include: force-pop + push: _expect-integer + - include: statement-separators helper-specs: diff --git a/syntax_test_Nftables.nft b/syntax_test_Nftables.nft index 837bc3a..94a56db 100644 --- a/syntax_test_Nftables.nft +++ b/syntax_test_Nftables.nft @@ -114,7 +114,7 @@ add filter input position 1 ip saddr $ntp_servers counter # ^ variable.other.readwrite.table.nftables # ^ variable.other.readwrite.chain.nftables # ^ keyword.other.handle.nftables -# ^ constant.numeric.integer.signed.nftables +# ^ constant.numeric.integer.nftables # ^ punctuation.definition.variable.nftables # ^ variable.other.constant.nftables # ^ keyword.control.rule-statement.nftables