Skip to content

Commit

Permalink
Change scope of arguments to be more specific
Browse files Browse the repository at this point in the history
This includes moving process expansion to be a subtype of
the argument scope, and identifying possible file paths

Also reordered a scope and fixed a typo
  • Loading branch information
Phidica committed Apr 16, 2019
1 parent 3a69a8e commit ccbdb38
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
Improvements:
- Support the `[ ]` form of `test` (#8)
- Highlight a `~` in redirect paths
- Distinguish arguments which might be paths with `meta.parameter.argument.path`
- Distinguish option and argument parameter types, and long and short option types (as well as the "end of options" option).
We now provide the following scopes:
- `meta.parameter.option.long`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ Exposed scopes
| Unquoted string | `meta.string.unquoted`
| File path (in redirection) | `meta.redirection.path`
| Variable expansion | `meta.variable-expansion` and `punctuation.definition.variable`
| Process expansion | `meta.process-expansion` and `punctuation.definition.process`
| Process expansion | `meta.parameter.argument.process-expansion` and `punctuation.definition.process`
| Command substitution | `meta.parens.command-substitution` and `punctuation.section.parens.begin`/`end`
| Index expansion | `meta.brackets.index-expansion` and `punctuation.section.brackets.begin`/`end`
| Brace expansion | `meta.braces.brace-expansion` and `punctuation.section.braces.begin`/`separator`/`end`
| Home directory expansion | `meta.home-directory-expansion` and `keyword.operator.tilde`
| Home directory expansion | `meta.parameter.argument.path` and `keyword.operator.tilde`
| Wildcard expansion | `meta.wildcard-expansion` and `keyword.operator.question-mark`/`single-star`/`double-star`

Contribution
Expand Down
12 changes: 6 additions & 6 deletions Tools/syntax_test_fish.fish
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo ~foo \~bar~\~ %foo \%bar%\%
#! ^^^^^^^^ meta.string.unquoted
#! ^ - keyword.operator.tilde
#! ^^ constant.character.escape
#! ^^^^ meta.process-expansion
#! ^^^^ meta.parameter.argument.process-expansion
#! ^ punctuation.definition.process
#! ^^^^^^^^ meta.string.unquoted
#! ^^ constant.character.escape
Expand Down Expand Up @@ -793,26 +793,26 @@ echo one{, ,\ }two
#! ^^ constant.character.escape

echo %"fish" one%two %%percent
#! ^^^^^^^ meta.process-expansion
#! ^^^^^^^ meta.parameter.argument.process-expansion
#! ^ punctuation.definition.process
#! ^^^^^^ string.quoted
#! ^^^^^^^ meta.string.unquoted
#! ^^^^^^^^^ meta.process-expansion
#! ^^^^^^^^^ meta.parameter.argument.process-expansion
#! ^ punctuation.definition.process
#! ^^^^^^^^ meta.string.unquoted

echo %fi\
sh>out
#! <- meta.process-expansion
#! <- meta.parameter.argument.process-expansion
#! ^^^ meta.redirection

echo %self foo %(set foo "fi"; echo $foo)sh "bar"
#! ^^^^^ meta.process-expansion
#! ^^^^^ meta.parameter.argument.process-expansion
#! ^ punctuation.definition.process
#! ^^^ meta.string.unquoted
#! ^ punctuation.definition.process
#! ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.parens.command-substitution
#! ^^ meta.process-expansion
#! ^^ meta.parameter.argument.process-expansion
#! ^^^^^ string.quoted

echo %self>out
Expand Down
27 changes: 17 additions & 10 deletions fish.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -135,34 +135,41 @@ repository:
comment: This rule must be entirely standalone because it is used in scopes where parameters starting with hyphens are explicitly interpreted as arguments rather than as options
patterns:
- comment: A parameter is a fundamental unit of a command call, defined as a sequence of non-operator characters separated by unescaped and unscoped whitespace
name: meta.parameter.argument.fish
begin: (?![\s;&)|<>^])
comment: Begin arg if it does not precede whitespace or an operator
end: (?=[\s;&)|<>])
comment: End arg if it precedes whitespace or operators (excluding stderr redirect '^' due to a fish quirk)
patterns:
- comment: Home directory expansion only occurs if the '~' is at the front of the argument
name: meta.string.unquoted.fish meta.home-directory-expansion.fish keyword.operator.tilde.fish
match: \~

- comment: Process expansion only occurs if the '%' is at the front of the argument, and continues for the entire argument
name: meta.process-expansion.fish
name: meta.parameter.argument.process-expansion.fish
begin: \%
beginCaptures:
'0': {name: meta.string.unquoted.fish punctuation.definition.process.fish}
end: (?=[\s;&)|<>])
patterns:
- comment: Match special process names. By a convention that I'm making up, scope them as a type of variable
name: variable.language.fish meta.string.unquoted.fish
name: meta.string.unquoted.fish variable.language.fish
match: (?:self|last)(?=$|[\s;&)|<>])

- include: '#parameter-patterns'

- comment: Treat a sequence of integers (with possible sign and decimal separator) as a standalone constant. Do this separate to the #string-unquoted-pattens rule so we can ensure it is a string solely of numbers
name: meta.string.unquoted.fish constant.numeric.fish
- comment: Treat a sequence of integers (with possible sign and decimal separator) as a standalone constant. Do this separate to the #string-unquoted-patterns rule so we can ensure it is a string solely of numbers
name: meta.parameter.argument.numeric.fish meta.string.unquoted.fish constant.numeric.fish
match: (?:[+-]?)(?:[0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(?=$|[\s;&)|<>])

- comment: Use standard parameter patterns exclusively for the remainder of the argument
- comment: This scope can be used by plugins to locate arguments which don't *start* with command substitution or variable expansion and may directly resolve to file paths. Of course, they could have command substitution or variable expansion further on in them, but looking ahead for that too is nontrivial
name: meta.parameter.argument.path.fish
begin: (?![\s($])
end: (?=[\s;&)|<>])
patterns:
- comment: Home directory expansion only occurs if the '~' is at the front of the argument, so check it first
name: meta.string.unquoted.fish keyword.operator.tilde.fish
match: \~

- include: '#parameter-patterns'

- comment: Use standard parameter patterns for whatever doesn't match the above
name: meta.parameter.argument.fish
begin: (?!\s)
end: (?=[\s;&)|<>])
patterns:
Expand Down
45 changes: 31 additions & 14 deletions fish.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,8 @@
<string>End arg if it precedes whitespace or operators (excluding stderr redirect '^' due to a fish quirk)</string>
<key>end</key>
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>meta.parameter.argument.fish</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>Home directory expansion only occurs if the '~' is at the front of the argument</string>
<key>match</key>
<string>\~</string>
<key>name</key>
<string>meta.string.unquoted.fish meta.home-directory-expansion.fish keyword.operator.tilde.fish</string>
</dict>
<dict>
<key>begin</key>
<string>\%</string>
Expand All @@ -136,7 +126,7 @@
<key>end</key>
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>meta.process-expansion.fish</string>
<string>meta.parameter.argument.process-expansion.fish</string>
<key>patterns</key>
<array>
<dict>
Expand All @@ -145,7 +135,7 @@
<key>match</key>
<string>(?:self|last)(?=$|[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>variable.language.fish meta.string.unquoted.fish</string>
<string>meta.string.unquoted.fish variable.language.fish</string>
</dict>
<dict>
<key>include</key>
Expand All @@ -159,15 +149,42 @@
<key>match</key>
<string>(?:[+-]?)(?:[0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(?=$|[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>meta.string.unquoted.fish constant.numeric.fish</string>
<string>meta.parameter.argument.numeric.fish meta.string.unquoted.fish constant.numeric.fish</string>
</dict>
<dict>
<key>begin</key>
<string>(?![\s($])</string>
<key>comment</key>
<string>This scope can be used by plugins to locate arguments which don't *start* with command substitution or variable expansion and may directly resolve to file paths. Of course, they could have command substitution or variable expansion further on in them, but looking ahead for that too is nontrivial</string>
<key>end</key>
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>meta.parameter.argument.path.fish</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>Home directory expansion only occurs if the '~' is at the front of the argument, so check it first</string>
<key>match</key>
<string>\~</string>
<key>name</key>
<string>meta.string.unquoted.fish keyword.operator.tilde.fish</string>
</dict>
<dict>
<key>include</key>
<string>#parameter-patterns</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(?!\s)</string>
<key>comment</key>
<string>Use standard parameter patterns exclusively for the remainder of the argument</string>
<string>Use standard parameter patterns for whatever doesn't match the above</string>
<key>end</key>
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>name</key>
<string>meta.parameter.argument.fish</string>
<key>patterns</key>
<array>
<dict>
Expand Down

0 comments on commit ccbdb38

Please sign in to comment.