Skip to content

Commit

Permalink
fish: Fix incorrect tokenisation of command arguments containing dash
Browse files Browse the repository at this point in the history
Command line arguments containing dash/hyphen were incorrectly
tokenised as command line options.
  • Loading branch information
CIAvash authored and alecthomas committed Jun 17, 2021
1 parent 841c391 commit 9df8bd4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lexers/f/fish.go
Expand Up @@ -74,7 +74,7 @@ func fishRules() Rules {
{`&&|\|\||&|\||\^|<|>`, Operator, nil},
{`\s+`, Text, nil},
{`\b\d+\b`, LiteralNumber, nil},
{`--?[^\d][\w-]*`, NameAttribute, nil},
{`(?<=\s+)--?[^\d][\w-]*`, NameAttribute, nil},
{".+?", Text, nil},
},
"string": {
Expand Down
4 changes: 3 additions & 1 deletion lexers/testdata/fish.actual
Expand Up @@ -24,6 +24,8 @@ set data (cat data | string split0)

grep fish myanimallist1 | wc -l

command some-arg-with-dash

echo input.{c,h,txt}

echo {$dogs}dog
Expand Down Expand Up @@ -241,4 +243,4 @@ function fish_config --description "Launch fish's web based configuration"
end

return 0
end
end
7 changes: 5 additions & 2 deletions lexers/testdata/fish.expected
Expand Up @@ -94,6 +94,8 @@
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"-l"},
{"type":"Text","value":"\n\n"},
{"type":"NameBuiltin","value":"command "},
{"type":"Text","value":"some-arg-with-dash\n\n"},
{"type":"Keyword","value":"echo"},
{"type":"Text","value":" input."},
{"type":"Operator","value":"{"},
Expand Down Expand Up @@ -865,7 +867,7 @@
{"type":"Text","value":" "},
{"type":"Operator","value":"("},
{"type":"NameBuiltin","value":"status fish"},
{"type":"NameAttribute","value":"-path"},
{"type":"Text","value":"-path"},
{"type":"Operator","value":")"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"set"},
Expand Down Expand Up @@ -1261,5 +1263,6 @@
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"0"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"end"}
{"type":"Keyword","value":"end"},
{"type":"Text","value":"\n"}
]

0 comments on commit 9df8bd4

Please sign in to comment.