Skip to content

Commit

Permalink
[INTERNAL] [IMPORTANT] Stack management rework, please read below :
Browse files Browse the repository at this point in the history
`push` followed by `include` statements were not working as expected, due to unconsumed white-space characters.
See <https://forum.sublimetext.com/t/syntax-definitions-how-to-force-pop-out-of-the-stack/36376/4>.

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 <sublimehq/Packages#757 (comment)> 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.
  • Loading branch information
Samuel FORESTIER committed Mar 16, 2020
1 parent 549fc88 commit fa39f9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions Nftables.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ variables:
integer: (?:[[:digit:]]+)
hexadecimal: (?:(?:0x)[[:xdigit:]]+)

time_string: (?:(?:\d+[wdhms])+)
identifier: (?:[[:alpha:]][[:alnum:]_]*)
identifier_extended: (?:[[:alpha:]][[:alnum:]_\-]*)

Expand Down Expand Up @@ -64,10 +65,6 @@ contexts:
- include: variables
- include: line-continuation

force-pop:
- match: ''
pop: true

comments:
- match: (#)
scope: punctuation.definition.comment.nftables
Expand Down Expand Up @@ -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}})
Expand Down Expand Up @@ -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: ({)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion syntax_test_Nftables.nft
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa39f9d

Please sign in to comment.