Skip to content

Commit 8fa488c

Browse files
authored
Fix Gleam lexer (#1072)
I made the Gleam lexer *dumber* (that is, more acquiescent), but it fixes #1054 and still passes the tests.
1 parent 211957a commit 8fa488c

File tree

3 files changed

+92
-22
lines changed

3 files changed

+92
-22
lines changed

lexers/embedded/gleam.xml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
</rule>
3434
<rule pattern="(type)\b">
3535
<token type="Keyword"/>
36-
<push state="typename"/>
3736
</rule>
3837
<rule pattern="(True|False)\b">
3938
<token type="KeywordConstant"/>
@@ -63,39 +62,23 @@
6362
<rule pattern="[{}()\[\],]|[#(]|\.\.|&lt;&gt;|&lt;&lt;|&gt;&gt;">
6463
<token type="Punctuation"/>
6564
</rule>
66-
<rule pattern="[+\-*/%!=&lt;&gt;&amp;|.]|&lt;-">
65+
<rule pattern=":|-&gt;">
6766
<token type="Operator"/>
6867
</rule>
69-
<rule pattern=":|-&gt;">
68+
<rule pattern="[+\-*/%!=&lt;&gt;&amp;|.]|&lt;-">
7069
<token type="Operator"/>
71-
<push state="typename"/>
7270
</rule>
7371
<rule pattern="([a-z_][A-Za-z0-9_]*)(\()">
7472
<bygroups>
7573
<token type="NameFunction"/>
7674
<token type="Punctuation"/>
7775
</bygroups>
7876
</rule>
79-
<rule pattern="([A-Z][A-Za-z0-9_]*)(\()">
80-
<bygroups>
81-
<token type="NameClass"/>
82-
<token type="Punctuation"/>
83-
</bygroups>
84-
</rule>
85-
<rule pattern="([a-z_]\w*[!?]?)">
86-
<token type="Name"/>
87-
</rule>
88-
</state>
89-
<state name="typename">
90-
<rule pattern="\s+">
91-
<token type="TextWhitespace"/>
92-
</rule>
9377
<rule pattern="[A-Z][A-Za-z0-9_]*">
9478
<token type="NameClass"/>
95-
<pop depth="1"/>
9679
</rule>
97-
<rule>
98-
<pop depth="1"/>
80+
<rule pattern="([a-z_]\w*[!?]?)">
81+
<token type="Name"/>
9982
</rule>
10083
</state>
10184
<state name="string">

lexers/testdata/gleam.actual

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ pub fn main() {
1818
io.debug(reverse_list([1, 2, 3, 4, 5]))
1919
io.debug(reverse_list(["a", "b", "c", "d", "e"]))
2020
}
21+
22+
pub fn plus_one(x: Int) -> Int {
23+
x + 1
24+
}
25+
26+
pub type Message {
27+
RegisterFeed(String, Poller)
28+
}
29+
30+
pub type Table = Subject(Message)
31+
32+
pub fn start() -> Table {
33+
todo
34+
}

lexers/testdata/gleam.expected

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,78 @@
181181
{"type":"Punctuation","value":"]))"},
182182
{"type":"TextWhitespace","value":"\n"},
183183
{"type":"Punctuation","value":"}"},
184-
{"type":"TextWhitespace","value":"\n"}
184+
{"type":"TextWhitespace","value":"\n\n"},
185+
{"type":"Keyword","value":"pub"},
186+
{"type":"TextWhitespace","value":" "},
187+
{"type":"Keyword","value":"fn"},
188+
{"type":"TextWhitespace","value":" "},
189+
{"type":"NameFunction","value":"plus_one"},
190+
{"type":"Punctuation","value":"("},
191+
{"type":"Name","value":"x"},
192+
{"type":"Operator","value":":"},
193+
{"type":"TextWhitespace","value":" "},
194+
{"type":"NameClass","value":"Int"},
195+
{"type":"Punctuation","value":")"},
196+
{"type":"TextWhitespace","value":" "},
197+
{"type":"Operator","value":"-\u003e"},
198+
{"type":"TextWhitespace","value":" "},
199+
{"type":"NameClass","value":"Int"},
200+
{"type":"TextWhitespace","value":" "},
201+
{"type":"Punctuation","value":"{"},
202+
{"type":"TextWhitespace","value":"\n "},
203+
{"type":"Name","value":"x"},
204+
{"type":"TextWhitespace","value":" "},
205+
{"type":"Operator","value":"+"},
206+
{"type":"TextWhitespace","value":" "},
207+
{"type":"LiteralNumberInteger","value":"1"},
208+
{"type":"TextWhitespace","value":"\n"},
209+
{"type":"Punctuation","value":"}"},
210+
{"type":"TextWhitespace","value":"\n\n"},
211+
{"type":"Keyword","value":"pub"},
212+
{"type":"TextWhitespace","value":" "},
213+
{"type":"Keyword","value":"type"},
214+
{"type":"TextWhitespace","value":" "},
215+
{"type":"NameClass","value":"Message"},
216+
{"type":"TextWhitespace","value":" "},
217+
{"type":"Punctuation","value":"{"},
218+
{"type":"TextWhitespace","value":"\n "},
219+
{"type":"NameClass","value":"RegisterFeed"},
220+
{"type":"Punctuation","value":"("},
221+
{"type":"NameClass","value":"String"},
222+
{"type":"Punctuation","value":","},
223+
{"type":"TextWhitespace","value":" "},
224+
{"type":"NameClass","value":"Poller"},
225+
{"type":"Punctuation","value":")"},
226+
{"type":"TextWhitespace","value":"\n"},
227+
{"type":"Punctuation","value":"}"},
228+
{"type":"TextWhitespace","value":"\n\n"},
229+
{"type":"Keyword","value":"pub"},
230+
{"type":"TextWhitespace","value":" "},
231+
{"type":"Keyword","value":"type"},
232+
{"type":"TextWhitespace","value":" "},
233+
{"type":"NameClass","value":"Table"},
234+
{"type":"TextWhitespace","value":" "},
235+
{"type":"Operator","value":"="},
236+
{"type":"TextWhitespace","value":" "},
237+
{"type":"NameClass","value":"Subject"},
238+
{"type":"Punctuation","value":"("},
239+
{"type":"NameClass","value":"Message"},
240+
{"type":"Punctuation","value":")"},
241+
{"type":"TextWhitespace","value":"\n\n"},
242+
{"type":"Keyword","value":"pub"},
243+
{"type":"TextWhitespace","value":" "},
244+
{"type":"Keyword","value":"fn"},
245+
{"type":"TextWhitespace","value":" "},
246+
{"type":"NameFunction","value":"start"},
247+
{"type":"Punctuation","value":"()"},
248+
{"type":"TextWhitespace","value":" "},
249+
{"type":"Operator","value":"-\u003e"},
250+
{"type":"TextWhitespace","value":" "},
251+
{"type":"NameClass","value":"Table"},
252+
{"type":"TextWhitespace","value":" "},
253+
{"type":"Punctuation","value":"{"},
254+
{"type":"TextWhitespace","value":"\n "},
255+
{"type":"Keyword","value":"todo"},
256+
{"type":"TextWhitespace","value":"\n"},
257+
{"type":"Punctuation","value":"}"}
185258
]

0 commit comments

Comments
 (0)