Skip to content

Commit 04942d7

Browse files
committed
lexers: Add GNU Assembler lexer tests
1 parent c5b6c08 commit 04942d7

1 file changed

Lines changed: 282 additions & 0 deletions

File tree

elixir/lexers/tests/test_gas.py

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
from ..lexers import GasLexer
2+
from .base import LexerTest
3+
4+
class GasLexerTest(LexerTest):
5+
lexer_cls = GasLexer
6+
default_filtered_tokens = ("SPECIAL", "COMMENT", "STRING", "IDENTIFIER", "SPECIAL", "ERROR")
7+
8+
def test_comments_m68k(self):
9+
self.lex(r"""
10+
# comment 1
11+
#comment 2
12+
clrl d1 | comment 3
13+
clrl d0 |comment 4
14+
| comment 4
15+
16+
clrl d2 # comment 3
17+
18+
#if defined(C1) || !defined(C2)
19+
addql #4,%sp
20+
label:
21+
movel #-IDNENT,%sp@(IDENT)| comment 5
22+
// /linux/v6.10.7/source/arch/m68k/ifpsp060/src/fplsp.S
23+
test # comment 6
24+
# endif
25+
26+
#define macro(x) inst &IDENT,%pc@(ident); inst x
27+
""", [
28+
['COMMENT', '# comment 1\n'],
29+
['COMMENT', '#comment 2\n'],
30+
['IDENTIFIER', 'clrl'],
31+
['IDENTIFIER', 'd1'],
32+
['COMMENT', '| comment 3\n'],
33+
['IDENTIFIER', 'clrl'],
34+
['IDENTIFIER', 'd0'],
35+
['COMMENT', '|comment 4\n'],
36+
['COMMENT', '| comment 4\n'],
37+
['IDENTIFIER', 'clrl'],
38+
['IDENTIFIER', 'd2'],
39+
['COMMENT', '# comment 3\n'],
40+
['SPECIAL', '#if'],
41+
['IDENTIFIER', 'defined'],
42+
['IDENTIFIER', 'C1'],
43+
['IDENTIFIER', 'defined'],
44+
['IDENTIFIER', 'C2'],
45+
['IDENTIFIER', 'addql'],
46+
['IDENTIFIER', 'sp'],
47+
['IDENTIFIER', 'label'],
48+
['IDENTIFIER', 'movel'],
49+
['IDENTIFIER', 'IDNENT'],
50+
['IDENTIFIER', 'sp'],
51+
['IDENTIFIER', 'IDENT'],
52+
['COMMENT', '| comment 5\n'],
53+
['COMMENT', '// /linux/v6.10.7/source/arch/m68k/ifpsp060/src/fplsp.S\n'],
54+
['IDENTIFIER', 'test'],
55+
['COMMENT', '# comment 6\n'],
56+
['SPECIAL', '# endif'],
57+
['SPECIAL', '#define'],
58+
['IDENTIFIER', 'macro'],
59+
['IDENTIFIER', 'x'],
60+
['IDENTIFIER', 'inst'],
61+
['IDENTIFIER', 'IDENT'],
62+
['IDENTIFIER', 'pc'],
63+
['IDENTIFIER', 'ident'],
64+
['IDENTIFIER', 'inst'],
65+
['IDENTIFIER', 'x'],
66+
], lexer_options={"arch": "m68k"})
67+
68+
def test_comments_sparc(self):
69+
self.lex(r"""
70+
#define F(i) \
71+
.type i,@function;
72+
73+
std t1, [0x00];
74+
75+
/*comment default */
76+
//comment default2
77+
.type identifier,#function
78+
label:
79+
sethi %hi(IDENT), %g0 !test comment
80+
wrpr %g1, %sp ! test comment
81+
# comment
82+
#comment
83+
sethi %hi(IDENT_1 | IDENT_2), %l0
84+
""", [
85+
['SPECIAL', '#define'],
86+
['IDENTIFIER', 'F'],
87+
['IDENTIFIER', 'i'],
88+
['IDENTIFIER', 'type'],
89+
['IDENTIFIER', 'i'],
90+
['IDENTIFIER', 'function'],
91+
['IDENTIFIER', 'std'],
92+
['IDENTIFIER', 't1'],
93+
['COMMENT', '/*comment default */'],
94+
['COMMENT', '//comment default2\n'],
95+
['IDENTIFIER', 'type'],
96+
['IDENTIFIER', 'identifier'],
97+
['IDENTIFIER', 'function'],
98+
['IDENTIFIER', 'label'],
99+
['IDENTIFIER', 'sethi'],
100+
['IDENTIFIER', 'hi'],
101+
['IDENTIFIER', 'IDENT'],
102+
['IDENTIFIER', 'g0'],
103+
['COMMENT', '!test comment\n'],
104+
['IDENTIFIER', 'wrpr'],
105+
['IDENTIFIER', 'g1'],
106+
['IDENTIFIER', 'sp'],
107+
['COMMENT', '! test comment\n'],
108+
['COMMENT', '# comment\n'],
109+
['COMMENT', '#comment\n'],
110+
['IDENTIFIER', 'sethi'],
111+
['IDENTIFIER', 'hi'],
112+
['IDENTIFIER', 'IDENT_1'],
113+
['IDENTIFIER', 'IDENT_2'],
114+
['IDENTIFIER', 'l0'],
115+
], lexer_options={"arch": "sparc"})
116+
117+
def test_comments_arm32(self):
118+
self.lex(r"""
119+
// comment default
120+
/* comment default2 */
121+
test:
122+
bic r0, r1, #10
123+
# comment 1
124+
#comment 1
125+
"""
126+
+ "\t# comment 1" + r"""
127+
moveq r0, #IDENTIFIER @ Comment
128+
# comment 2
129+
#comment 2
130+
push {r0}
131+
add \addr, \addr, \tmp @comment3
132+
ldr r1, =TEST3
133+
ldr TEST, [sp, IDENT(i)];
134+
.long PMD_TYPE_SECT | \
135+
PMD_BIT4
136+
stmfd sp!, {r0, r1, r2, r3}
137+
eor RT0, d, b;
138+
""", [
139+
['COMMENT', '// comment default\n'],
140+
['COMMENT', '/* comment default2 */'],
141+
['IDENTIFIER', 'test'],
142+
['IDENTIFIER', 'bic'],
143+
['IDENTIFIER', 'r0'],
144+
['IDENTIFIER', 'r1'],
145+
['NUMBER', '10'],
146+
['COMMENT', '# comment 1\n'],
147+
['COMMENT', '#comment 1\n'],
148+
['COMMENT', '# comment 1\n'],
149+
['IDENTIFIER', 'moveq'],
150+
['IDENTIFIER', 'r0'],
151+
['IDENTIFIER', 'IDENTIFIER'],
152+
['COMMENT', '@ Comment\n'],
153+
['COMMENT', '# comment 2\n'],
154+
['COMMENT', '#comment 2\n'],
155+
['IDENTIFIER', 'push'],
156+
['IDENTIFIER', 'r0'],
157+
['IDENTIFIER', 'add'],
158+
['IDENTIFIER', 'addr'],
159+
['IDENTIFIER', 'addr'],
160+
['IDENTIFIER', 'tmp'],
161+
['COMMENT', '@comment3\n'],
162+
['IDENTIFIER', 'ldr'],
163+
['IDENTIFIER', 'r1'],
164+
['IDENTIFIER', 'TEST3'],
165+
['IDENTIFIER', 'ldr'],
166+
['IDENTIFIER', 'TEST'],
167+
['IDENTIFIER', 'sp'],
168+
['IDENTIFIER', 'IDENT'],
169+
['IDENTIFIER', 'i'],
170+
['IDENTIFIER', 'long'],
171+
['IDENTIFIER', 'PMD_TYPE_SECT'],
172+
['IDENTIFIER', 'PMD_BIT4'],
173+
['IDENTIFIER', 'stmfd'],
174+
['IDENTIFIER', 'sp'],
175+
['IDENTIFIER', 'r0'],
176+
['IDENTIFIER', 'r1'],
177+
['IDENTIFIER', 'r2'],
178+
['IDENTIFIER', 'r3'],
179+
['IDENTIFIER', 'eor'],
180+
['IDENTIFIER', 'RT0'],
181+
['IDENTIFIER', 'd'],
182+
['IDENTIFIER', 'b'],
183+
], self.default_filtered_tokens + ("NUMBER",), {"arch": "arm32"})
184+
185+
def test_comments_generic(self):
186+
self.lex(r"""
187+
/* comment
188+
* more comment
189+
* more comment
190+
*/
191+
mov r0, r1 //test
192+
mov x0, #IDENT
193+
stp x1, x2, [sp, #-4]!
194+
#if defined(IDENT1) || defined(IDENT2)
195+
#endif
196+
""", [
197+
['COMMENT', '/* comment\n * more comment\n * more comment\n */'],
198+
['IDENTIFIER', 'mov'],
199+
['IDENTIFIER', 'r0'],
200+
['PUNCTUATION', ','],
201+
['IDENTIFIER', 'r1'],
202+
['COMMENT', '//test\n'],
203+
['IDENTIFIER', 'mov'],
204+
['IDENTIFIER', 'x0'],
205+
['PUNCTUATION', ','],
206+
['PUNCTUATION', '#'],
207+
['IDENTIFIER', 'IDENT'],
208+
['IDENTIFIER', 'stp'],
209+
['IDENTIFIER', 'x1'],
210+
['PUNCTUATION', ','],
211+
['IDENTIFIER', 'x2'],
212+
['PUNCTUATION', ','],
213+
['PUNCTUATION', '['],
214+
['IDENTIFIER', 'sp'],
215+
['PUNCTUATION', ','],
216+
['PUNCTUATION', '#'],
217+
['PUNCTUATION', '-'],
218+
['NUMBER', '4'],
219+
['PUNCTUATION', ']'],
220+
['PUNCTUATION', '!'],
221+
['SPECIAL', '#if'],
222+
['IDENTIFIER', 'defined'],
223+
['PUNCTUATION', '('],
224+
['IDENTIFIER', 'IDENT1'],
225+
['PUNCTUATION', ')'],
226+
['PUNCTUATION', '||'],
227+
['IDENTIFIER', 'defined'],
228+
['PUNCTUATION', '('],
229+
['IDENTIFIER', 'IDENT2'],
230+
['PUNCTUATION', ')'],
231+
['SPECIAL', '#endif'],
232+
], self.default_filtered_tokens + ("PUNCTUATION", "NUMBER"))
233+
234+
def test_comments_preproc(self):
235+
self.lex(r"""
236+
# error "test"
237+
#warning "test"
238+
#include "test.h"
239+
#include <test.h>
240+
#if defined(T1) || defined(T2)
241+
#endif
242+
""", [
243+
['SPECIAL', '# error "test"\n'],
244+
['SPECIAL', '#warning "test"\n'],
245+
['SPECIAL', '#include "test.h"'],
246+
['SPECIAL', '#include <test.h>'],
247+
['SPECIAL', '#if'],
248+
['IDENTIFIER', 'defined'],
249+
['IDENTIFIER', 'T1'],
250+
['IDENTIFIER', 'defined'],
251+
['IDENTIFIER', 'T2'],
252+
['SPECIAL', '#endif'],
253+
])
254+
255+
def test_comments_literals(self):
256+
self.lex(r"""
257+
.byte 12, 0b1010, 0B1010, 0x34, 0123, 0X45, 'a, '\b
258+
.ascii "asdsad\"zxczc"
259+
.float 0f-12321321030982394324\
260+
21321432432.234324324E-14
261+
.float 0f-123.123213e+13
262+
.float 0e-123.123213e+13
263+
""", [
264+
['IDENTIFIER', 'byte'],
265+
['NUMBER', '12'],
266+
['NUMBER', '0b1010'],
267+
['NUMBER', '0B1010'],
268+
['NUMBER', '0x34'],
269+
['NUMBER', '0123'],
270+
['NUMBER', '0X45'],
271+
['STRING', "'a"],
272+
['STRING', "'\\b"],
273+
['IDENTIFIER', 'ascii'],
274+
['STRING', '"asdsad\\"zxczc"'],
275+
['IDENTIFIER', 'float'],
276+
['NUMBER', '0f-12321321030982394324\\\n 21321432432.234324324E-14'],
277+
['IDENTIFIER', 'float'],
278+
['NUMBER', '0f-123.123213e+13'],
279+
['IDENTIFIER', 'float'],
280+
['NUMBER', '0e-123.123213e+13'],
281+
], self.default_filtered_tokens + ("NUMBER",))
282+

0 commit comments

Comments
 (0)