Skip to content

Commit 9df8bd4

Browse files
CIAvashalecthomas
authored andcommitted
fish: Fix incorrect tokenisation of command arguments containing dash
Command line arguments containing dash/hyphen were incorrectly tokenised as command line options.
1 parent 841c391 commit 9df8bd4

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: lexers/f/fish.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func fishRules() Rules {
7474
{`&&|\|\||&|\||\^|<|>`, Operator, nil},
7575
{`\s+`, Text, nil},
7676
{`\b\d+\b`, LiteralNumber, nil},
77-
{`--?[^\d][\w-]*`, NameAttribute, nil},
77+
{`(?<=\s+)--?[^\d][\w-]*`, NameAttribute, nil},
7878
{".+?", Text, nil},
7979
},
8080
"string": {

Diff for: lexers/testdata/fish.actual

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ set data (cat data | string split0)
2424

2525
grep fish myanimallist1 | wc -l
2626

27+
command some-arg-with-dash
28+
2729
echo input.{c,h,txt}
2830

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

243245
return 0
244-
end
246+
end

Diff for: lexers/testdata/fish.expected

+5-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
{"type":"Text","value":" "},
9595
{"type":"NameAttribute","value":"-l"},
9696
{"type":"Text","value":"\n\n"},
97+
{"type":"NameBuiltin","value":"command "},
98+
{"type":"Text","value":"some-arg-with-dash\n\n"},
9799
{"type":"Keyword","value":"echo"},
98100
{"type":"Text","value":" input."},
99101
{"type":"Operator","value":"{"},
@@ -865,7 +867,7 @@
865867
{"type":"Text","value":" "},
866868
{"type":"Operator","value":"("},
867869
{"type":"NameBuiltin","value":"status fish"},
868-
{"type":"NameAttribute","value":"-path"},
870+
{"type":"Text","value":"-path"},
869871
{"type":"Operator","value":")"},
870872
{"type":"Text","value":"\n "},
871873
{"type":"Keyword","value":"set"},
@@ -1261,5 +1263,6 @@
12611263
{"type":"Text","value":" "},
12621264
{"type":"LiteralNumber","value":"0"},
12631265
{"type":"Text","value":"\n "},
1264-
{"type":"Keyword","value":"end"}
1266+
{"type":"Keyword","value":"end"},
1267+
{"type":"Text","value":"\n"}
12651268
]

0 commit comments

Comments
 (0)