Skip to content

Commit

Permalink
Fix bug where '=' could not safely be a command name
Browse files Browse the repository at this point in the history
I also switched to a much safer internal approach to needing '='
unmatched by the #string-unquoted rule such that the long option
argument pattern can find it. Instead of excluding '=' from all
unquoted strings in general and requiring manual treatment of it
every time, just recreate a modified #string-unquoted rule in the
one instance it is required!
  • Loading branch information
Phidica committed Oct 24, 2017
1 parent 920e2c6 commit 6efc4c2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
40 changes: 21 additions & 19 deletions fish.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,29 @@ repository:
'0': {name: punctuation.definition.parameter.fish meta.string.unquoted.fish}
end: (?=[\s;&)|<>]|=)
patterns:
- include: '#argument-patterns'
- comment: We mimic the argument-patterns rule but use a tweaked unquoted string pattern which excludes '='
- include: '#command-substitution'

- name: meta.string.unquoted.fish
begin: (?=\$)
end: (?!\$)
patterns:
- include: '#variable-expansion'

- include: '#string-quoted'

- name: meta.string.unquoted.fish
begin: (?!['"])
end: (?=[\s;&()|<>'"$]|\=)
patterns:
- include: '#string-unquoted-patterns'

- comment: Consume the '=' and then use standard argument patterns
begin: (?:=)
beginCaptures:
'0': {name: variable.parameter.fish punctuation.definition.parameter.separator.fish meta.string.unquoted.fish }
end: (?=[\s;&)|<>])
patterns:
- comment: Standard argument patterns
- name: meta.string.unquoted.fish
match: \=
- include: '#argument-patterns'

- comment: Argument starting with one dash (short option)
Expand All @@ -83,9 +95,6 @@ repository:
'0': {name: punctuation.definition.parameter.fish meta.string.unquoted.fish}
end: (?=[\s;&)|<>])
patterns:
- comment: Standard argument patterns
- name: meta.string.unquoted.fish
match: \=
- include: '#argument-patterns'

- comment: Argument starting with no dashes
Expand Down Expand Up @@ -116,19 +125,12 @@ repository:
name: variable.language.fish meta.string.unquoted.fish
match: (?:self|last)(?=[\s;&)|])

- comment: Standard argument patterns
- name: meta.string.unquoted.fish
match: \=
- include: '#argument-patterns'

- comment: Use standard argument patterns exclusively for the remainder of the argument
begin: (?!\s)
end: (?=[\s;&)|<>])
patterns:
- comment: Pick up characters excluded by the string rule
name: meta.string.unquoted.fish
match: \=

- include: '#argument-patterns'

argument-patterns:
Expand All @@ -143,7 +145,7 @@ repository:
patterns:
- include: '#variable-expansion'

- comment: Arguments are otherwise made of strings, either quoted or unquoted. The unquoted string rule handles numerics, character escapes, and the brace expansion. It excludes '=' though, so that the long option argument pattern can treat it as a special character
- comment: Arguments are otherwise made of strings, either quoted or unquoted. The unquoted string rule handles numerics, character escapes, and brace expansion
- include: '#string'

command-chain:
Expand Down Expand Up @@ -725,7 +727,7 @@ repository:

- include: '#variable-expansion'

- comment: Manually recreate the #string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope
- comment: Manually recreate the string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope
- include: '#string-quoted'
- name: constant.numeric.fish
match: (?:[0-9]+)(?=[\s;&)|<>'"]|\]|\.\.)
Expand Down Expand Up @@ -854,8 +856,8 @@ repository:
- name: meta.string.unquoted.fish
begin: (?!['"])
comment: Begin unquoted string if there are no quotes present
end: (?=[\s;&()|<>'"$=])
comment: End unquoted string at whitespace, control operators, quoted strings, a variable expansion, or an equals sign '=' (because the long option argument pattern needs to see it)
end: (?=[\s;&()|<>'"$])
comment: End unquoted string at whitespace, control operators, quoted strings, or a variable expansion
patterns:
- include: '#string-unquoted-patterns'

Expand Down Expand Up @@ -899,7 +901,7 @@ repository:

- include: '#variable-expansion'

- comment: Manually recreate the #string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope
- comment: Manually recreate the string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope
- include: '#string-quoted'
- name: constant.numeric.fish
match: (?:[0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(?=[\s;&)|<>'"]|\}|\,)
Expand Down
88 changes: 44 additions & 44 deletions fish.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,47 @@
<string>variable.parameter.fish</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>We mimic the argument-patterns rule but use a tweaked unquoted string pattern which excludes '='</string>
</dict>
<dict>
<key>include</key>
<string>#argument-patterns</string>
<string>#command-substitution</string>
</dict>
<dict>
<key>begin</key>
<string>(?=\$)</string>
<key>end</key>
<string>(?!\$)</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#variable-expansion</string>
</dict>
</array>
</dict>
<dict>
<key>include</key>
<string>#string-quoted</string>
</dict>
<dict>
<key>begin</key>
<string>(?!['"])</string>
<key>end</key>
<string>(?=[\s;&amp;()|&lt;&gt;'"$]|\=)</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#string-unquoted-patterns</string>
</dict>
</array>
</dict>
</array>
</dict>
Expand All @@ -157,16 +195,6 @@
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>Standard argument patterns</string>
</dict>
<dict>
<key>match</key>
<string>\=</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
</dict>
<dict>
<key>include</key>
<string>#argument-patterns</string>
Expand Down Expand Up @@ -194,16 +222,6 @@
<string>meta.argument.fish variable.parameter.fish</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>Standard argument patterns</string>
</dict>
<dict>
<key>match</key>
<string>\=</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
</dict>
<dict>
<key>include</key>
<string>#argument-patterns</string>
Expand Down Expand Up @@ -274,16 +292,6 @@
<key>name</key>
<string>variable.language.fish meta.string.unquoted.fish</string>
</dict>
<dict>
<key>comment</key>
<string>Standard argument patterns</string>
</dict>
<dict>
<key>match</key>
<string>\=</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
</dict>
<dict>
<key>include</key>
<string>#argument-patterns</string>
Expand All @@ -299,14 +307,6 @@
<string>(?=[\s;&amp;)|&lt;&gt;])</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>Pick up characters excluded by the string rule</string>
<key>match</key>
<string>\=</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
</dict>
<dict>
<key>include</key>
<string>#argument-patterns</string>
Expand Down Expand Up @@ -346,7 +346,7 @@
</dict>
<dict>
<key>comment</key>
<string>Arguments are otherwise made of strings, either quoted or unquoted. The unquoted string rule handles numerics, character escapes, and the brace expansion. It excludes '=' though, so that the long option argument pattern can treat it as a special character</string>
<string>Arguments are otherwise made of strings, either quoted or unquoted. The unquoted string rule handles numerics, character escapes, and brace expansion</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -1789,7 +1789,7 @@
</dict>
<dict>
<key>comment</key>
<string>Manually recreate the</string>
<string>Manually recreate the string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -2119,9 +2119,9 @@
<key>begin</key>
<string>(?!['"])</string>
<key>comment</key>
<string>End unquoted string at whitespace, control operators, quoted strings, a variable expansion, or an equals sign '=' (because the long option argument pattern needs to see it)</string>
<string>End unquoted string at whitespace, control operators, quoted strings, or a variable expansion</string>
<key>end</key>
<string>(?=[\s;&amp;()|&lt;&gt;'"$=])</string>
<string>(?=[\s;&amp;()|&lt;&gt;'"$])</string>
<key>name</key>
<string>meta.string.unquoted.fish</string>
<key>patterns</key>
Expand Down Expand Up @@ -2210,7 +2210,7 @@
</dict>
<dict>
<key>comment</key>
<string>Manually recreate the</string>
<string>Manually recreate the string rule with extra logic in unquoted strings, and don't repeat the meta.string.unquoted scope</string>
</dict>
<dict>
<key>include</key>
Expand Down
4 changes: 4 additions & 0 deletions syntax_test_fish.fish
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ echo --==
cmd
#! <- variable.function

= arg
#! <- variable.function meta.string.unquoted
#! ^^ meta.argument

echo str \ # not-comment \ # comment
#! ^^^ meta.string.unquoted
#! ^^^ meta.string.unquoted
Expand Down

0 comments on commit 6efc4c2

Please sign in to comment.