@@ -20,10 +20,18 @@ lex:add_rule('constant', lex:tag(lexer.CONSTANT, lex:word_match(lexer.CONSTANT))
2020lex :add_rule (' function' ,
2121 lex :tag (lexer .FUNCTION_BUILTIN , ' @' * lex :word_match (lexer .FUNCTION_BUILTIN )))
2222
23+ -- Bare functions (function calls without @).
24+ lex :add_rule (' function_call' ,
25+ lex :tag (lexer .FUNCTION , lexer .word * # (lexer .space ^ 0 * ' (' )))
26+
27+ -- Struct methods (word followed by dot and another word).
28+ lex :add_rule (' method' , lex :tag (lexer .FUNCTION , lexer .word * ' .' * lexer .word ))
29+
2330-- Strings.
31+ local raw_str = P (' \\\\ ' ) * lexer .range (' \n ' , false , false ) -- Multi-line strings
2432local sq_str = lexer .range (" '" , true ) -- Character/Byte literal
2533local dq_str = lexer .range (' "' , true ) -- String/Byte array literal
26- lex :add_rule (' string' , lex :tag (lexer .STRING , sq_str + dq_str ))
34+ lex :add_rule (' string' , lex :tag (lexer .STRING , raw_str + sq_str + dq_str ))
2735
2836-- Identifiers.
2937lex :add_rule (' identifier' , lex :tag (lexer .IDENTIFIER , lexer .word ))
@@ -34,23 +42,28 @@ local comment = lexer.to_eol('//', true) -- Single-line comments
3442lex :add_rule (' comment' , lex :tag (lexer .COMMENT , doc_comment + comment ))
3543
3644-- Numbers.
37- lex :add_rule (' number' , lex :tag (lexer .NUMBER , lexer .number ))
45+ local binary = P (' 0b' ) * S (' 01' )^ 1
46+ local octal = P (' 0o' ) * S (' 01234567' )^ 1
47+ local hex = P (' 0x' ) * S (' 0123456789abcdefABCDEF' )^ 1
48+ local decimal = lexer .number
49+ lex :add_rule (' number' , lex :tag (lexer .NUMBER , binary + octal + hex + decimal ))
3850
3951-- Operators.
40- lex :add_rule (' operator' , lex :tag (lexer .OPERATOR , S (' +-/*%<>!=^&|?~:;,.()[]{}' )))
52+ lex :add_rule (' operator' , lex :tag (lexer .OPERATOR , S (' +-/*%<>!=^&|?~:;,.()[]{}' ) +
53+ P (' **' ) + P (' <<' ) + P (' >>' ) + P (' ==' ) + P (' !=' ) + P (' <=' ) + P (' >=' )))
4154
4255-- Word lists
4356lex :set_word_list (lexer .KEYWORD , {
4457 -- Keywords.
45- ' inline' , ' pub' , ' fn' , ' comptime' , ' const' , ' extern ' , ' return' , ' var' , ' usingnamespace' ,
58+ ' inline' , ' pub' , ' fn' , ' comptime' , ' const' , ' return' , ' var' , ' usingnamespace' ,
4659 -- Defering code blocks.
4760 ' defer' , ' errdefer' ,
4861 -- Functions and structures related keywords.
4962 ' align' , ' allowzero' , ' noalias' , ' noinline' ,
5063 ' callconv' , ' packed' , ' linksection' , ' unreachable' , ' test' , ' asm' ,
5164 ' volatile' ,
5265 -- Parallelism and concurrency related keywords.
53- ' async' , ' await' , ' noasync' , ' suspend' , ' nosuspend' , ' resume' , ' threadlocalanyframe ' ,
66+ ' async' , ' await' , ' noasync' , ' suspend' , ' nosuspend' , ' resume' , ' threadlocal ' , ' anyframe ' ,
5467 -- Control flow: conditions and loops.
5568 ' if' , ' else' , ' orelse' , ' or' , ' and' , ' while' , ' for' , ' switch' , ' continue' , ' break' , ' catch' ,
5669 ' try' ,
@@ -71,48 +84,28 @@ lex:set_word_list(lexer.TYPE, {
7184 ' comptime_int' , ' comptime_float' -- Comptime types
7285})
7386
87+ -- https://ziglang.org/documentation/master/#Builtin-Functions
7488lex :set_word_list (lexer .FUNCTION_BUILTIN , {
75- -- Extensive list of @-prefixed built-in functions
76- ' addWithOverflow' , ' alignCast' , ' alignOf' , ' as' , ' asyncCall' , ' atomicLoad' , ' atomicRmw' ,
77- ' atomicStore' , ' bitCast' , ' bitOffsetOf' , ' boolToInt' , ' bitSizeOf' , ' breakpoint' , ' mulAdd' ,
78- ' byteSwap' , ' bitReverse' , ' byteOffsetOf' , ' call' , ' cDefine' , ' cImport' , ' cInclude' , ' clz' ,
79- ' cmpxchgStrong' , ' cmpxchgWeak' , ' compileError' , ' compileLog' , " constCast" , ' ctz' , ' cUndef' ,
80- ' divExact' , ' divFloor' , ' divTrunc' , ' embedFile' , ' enumToInt' , " enumFromInt" , " intFromEnum" ,
81- " errorCast" , ' errorName' , ' errorReturnTrace' , " errorFromInt" , ' errorToInt' , ' errSetCast' ,
82- ' export' , ' fence' , ' field' , ' fieldParentPtr' , ' floatCast' ,
83- " floatFromInt" , ' floatToInt' , ' frame' , ' Frame' , ' frameAddress' , ' frameSize' ,
84- ' hasDecl' , ' hasField' , ' import' , " intFromBool" , " intFromError" , " intFromFloat" ,
85- " inComptime" , ' intCast' , " intFromPtr" , ' intToEnum' , ' intToError' , ' intToFloat' , ' intToPtr' ,
86- ' memcpy' , ' memset' , ' wasmMemorySize' , ' wasmMemoryGrow' , ' mod' , ' mulWithOverflow' ,
87- " newStackCall" , " offsetOf" , " OpaqueType" , ' panic' , " prefetch" ,
88- ' popCount' , ' ptrCast' , " ptrFromInt" , ' ptrToInt' , ' reduce' , ' rem' , ' returnAddress' , " select" ,
89- ' setAlignStack' , ' setCold' , ' setEvalBranchQuota' , ' setFloatMode' , ' setRuntimeSafety' ,
89+ ' addrSpaceCast' , ' addWithOverflow' , ' alignCast' , ' alignOf' , ' as' , ' atomicLoad' , ' atomicRmw' ,
90+ ' atomicStore' , ' bitCast' , ' bitOffsetOf' , ' bitSizeOf' , ' branchHint' , ' breakpoint' , ' mulAdd' ,
91+ ' byteSwap' , ' bitReverse' , ' call' , ' cDefine' , ' cImport' , ' cInclude' , ' clz' , ' cmpxchgStrong' ,
92+ ' cmpxchgWeak' , ' compileError' , ' compileLog' , ' constCast' , ' ctz' , ' cUndef' ,
93+ ' cVaArg' , ' cVaCopy' , ' cVaEnd' , ' cVaStart' , ' divExact' , ' divFloor' , ' divTrunc' , ' embedFile' ,
94+ ' enumToInt' , ' enumFromInt' , ' intFromEnum' , ' errorCast' , ' errorName' , ' errorReturnTrace' ,
95+ ' errorFromInt' , ' export' , ' extern' , ' field' , ' fieldParentPtr' , ' floatCast' , ' floatFromInt' ,
96+ ' frameAddress' , ' hasDecl' , ' hasField' , ' import' , ' intFromBool' , ' intFromError' , ' intFromFloat' ,
97+ ' inComptime' , ' intCast' , ' intFromPtr' , ' memcpy' , ' memmove' , ' memset' ,
98+ ' wasmMemorySize' , ' wasmMemoryGrow' , ' mulWithOverflow' , ' panic' , ' prefetch' ,
99+ ' popCount' , ' ptrCast' , ' ptrFromInt' , ' reduce' , ' rem' , ' returnAddress' , ' select' ,
100+ ' setEvalBranchQuota' , ' setFloatMode' , ' setRuntimeSafety' ,
90101 ' shlExact' , ' shlWithOverflow' , ' shrExact' , ' shuffle' , ' sizeOf' , ' splat' ,
91102 ' src' , ' sqrt' , ' sin' , ' cos' , ' tan' , ' exp' , ' exp2' , ' log' , ' log2' , ' log10' ,
92- ' max' , ' min' , ' abs' , ' fabs' , ' floor' , ' ceil' , ' trap' , ' trunc' , ' round' ,
93- ' subWithOverflow' , ' tagName' , ' TagType' , ' This' , ' truncate' ,
94- ' Type' , ' typeInfo' , ' typeName' , ' TypeOf' , ' unionInit' , ' Vector' , ' volatileCast'
103+ ' max' , ' min' , ' mod' , ' abs' , ' floor' , ' ceil' , ' trap' , ' trunc' , ' round' ,
104+ ' subWithOverflow' , ' tagName' , ' This' , ' truncate' ,
105+ ' Type' , ' typeInfo' , ' typeName' , ' TypeOf' , ' unionInit' , ' Vector' , ' volatileCast' ,
106+ ' workGroupId' , ' workGroupSize' , ' workItemId'
95107})
96108
97- -- Strings.
98- local sq_str = P (' L' )^- 1 * lexer .range (" '" , true )
99- local dq_str = P (' L' )^- 1 * lexer .range (' "' , true )
100- lex :add_rule (' string' , token (lexer .STRING , sq_str + dq_str ))
101-
102- -- Identifiers.
103- lex :add_rule (' identifier' , token (lexer .IDENTIFIER , lexer .word ))
104-
105- -- Comments.
106- local doc_comment = lexer .to_eol (' ///' , true )
107- local comment = lexer .to_eol (' //' , true )
108- lex :add_rule (' comment' , token (lexer .COMMENT , doc_comment + comment ))
109-
110- -- Numbers.
111- lex :add_rule (' number' , token (lexer .NUMBER , lexer .number ))
112-
113- -- Operators.
114- lex :add_rule (' operator' , token (lexer .OPERATOR , ' ..' + S (' +-/*%<>!=^&|?~:;,.()[]{}' )))
115-
116109-- Special values.
117110lex :set_word_list (lexer .CONSTANT , {
118111 ' false' , ' true' , ' null' , ' undefined'
0 commit comments