Skip to content

Commit

Permalink
Highlight private terms and dynamic term references
Browse files Browse the repository at this point in the history
These are experimental, not yet standardized constructs. The syntax for
dynamic term references (-$term-var) was taken as chosen by an unofficial
Perl 6 Fluent implementation.

projectfluent/fluent#130
projectfluent/fluent#80 (comment)
  • Loading branch information
SirNickolas committed Mar 25, 2022
1 parent 55503ee commit 146aabc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
17 changes: 11 additions & 6 deletions Src/Fluent.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ variables:
group_comment: (\#\#)([^ \n]?)(.*\n?)
resource_comment: (\#\#\#)([^ \n]?)(.*\n?)
message_definition: ({{identifier}})\ *(=)\ *
term_definition: (-(?:{{identifier}})?)\ *(=)\ *
term_definition: (--?(?:{{identifier}})?)\ *(=)\ *
incomplete_message_definition: ({{identifier}})\ *(?:(.)(.*\n?))?
incomplete_term_definition: (-(?:{{identifier}})?)\ *(?:(.)(.*\n?))?
incomplete_term_definition: (--?(?:{{identifier}})?)\ *(?:(.)(.*\n?))?
# indentation: '[ \t]*'
# Due to a bug in ST3, this regex triggers a warning about compatibility.
# https://github.com/sublimehq/sublime_text/issues/2465
Expand All @@ -24,7 +24,7 @@ variables:
# of the indented syntax tests are failed. Switch to the previous pair of regexes when checking.
# https://github.com/sublimehq/sublime_text/issues/3438
indentation: (?:\ *|\t[ \t]*) # We have to be a bit stricter here.
indented_entry_end: ^(?={{indentation}}-?{{identifier}}\ *=) # And a lot looser here.
indented_entry_end: ^(?={{indentation}}-{0,2}{{identifier}}\ *=) # And a lot looser here.

# We treat many illegal constructs as valid to avoid disturbing the user while they are typing.
contexts:
Expand Down Expand Up @@ -394,7 +394,12 @@ contexts:
pop: true

term-reference:
- match: -(?:{{identifier}})?
- match: (-\$)(?:{{identifier}})?
scope: variable.other.dynamic-term.fluent
captures:
1: punctuation.definition.variable.fluent
pop: true
- match: --?(?:{{identifier}})?
scope: variable.other.term.fluent
pop: true

Expand All @@ -417,7 +422,7 @@ contexts:

positional-argument-value:
- include: closing-paren
- match: ({{identifier}}) *(:) # Named argument.
- match: (-?{{identifier}}) *(:) # Named argument.
captures:
1: variable.parameter.fluent
2: punctuation.separator.argument.value.fluent
Expand Down Expand Up @@ -463,7 +468,7 @@ contexts:
set: named-argument-value

named-argument-key:
- match: '{{identifier}}'
- match: -?{{identifier}}
scope: variable.parameter.fluent
set:
- include: argument-colon
Expand Down
2 changes: 1 addition & 1 deletion Src/Fluent.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
\ + # Indentation with spaces.
| \t [ \t]* # Indentation with tabs.
)?
[-.]? # Term or attribute sigil.
(?: --? | \.)? # Term or attribute sigil.
[A-Za-z] .* = \ * # Message, term, or attribute definition.
| (?: [^{]* \{)++ [^}]* # Placeable.
) $
Expand Down
14 changes: 12 additions & 2 deletions Tests/syntax_test_terms.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
-not-a-comment = # Number sign.
# ^^^^^^^^^^^^^^^ string.unquoted.fluent - comment

--private-term = Experimental feature
# <- meta.term.fluent entity.name.term.fluent
#^^^^^^^^^^^^^^^^^^ meta.term.fluent
#^^^^^^^^^^^^^ entity.name.term.fluent
# ^ keyword.operator.assignment.fluent
# ^^ string.unquoted.fluent

-incomplete
# <- meta.term.fluent entity.name.term.fluent
#^^^^^^^^^^ meta.term.fluent entity.name.term.fluent
Expand Down Expand Up @@ -74,6 +81,9 @@
# <- meta.term.fluent entity.name.term.fluent
#^^^ meta.term.fluent - invalid

--
#^ meta.term.fluent entity.name.term.fluent


## Multiline terms.

Expand Down Expand Up @@ -101,8 +111,8 @@

## Invalid terms.

--
#^ meta.term.fluent invalid.illegal.assignment-required.fluent
---
# ^ meta.term.fluent invalid.illegal.assignment-required.fluent

-_
#^ meta.term.fluent invalid.illegal.assignment-required.fluent
Expand Down

0 comments on commit 146aabc

Please sign in to comment.