mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-27 21:49:13 +02:00
Merge pull request #157 from kaushalmodi/nim_underscore
Allow standalone _ to be recognized as identifier in Nim
This commit is contained in:
commit
5d7fef2ae6
@ -31,6 +31,7 @@ var Nim = internal.Register(MustNewLexer(
|
||||
{`(v_?a_?r)\b`, KeywordDeclaration, nil},
|
||||
{`(i_?n_?t_?|i_?n_?t_?8_?|i_?n_?t_?1_?6_?|i_?n_?t_?3_?2_?|i_?n_?t_?6_?4_?|f_?l_?o_?a_?t_?|f_?l_?o_?a_?t_?3_?2_?|f_?l_?o_?a_?t_?6_?4_?|b_?o_?o_?l_?|c_?h_?a_?r_?|r_?a_?n_?g_?e_?|a_?r_?r_?a_?y_?|s_?e_?q_?|s_?e_?t_?|s_?t_?r_?i_?n_?g_?)\b`, KeywordType, nil},
|
||||
{`(n_?i_?l_?|t_?r_?u_?e_?|f_?a_?l_?s_?e_?)\b`, KeywordPseudo, nil},
|
||||
{`\b_\b`, Name, nil}, // Standalone _ used as discardable variable identifier
|
||||
{`\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*`, Name, nil},
|
||||
{`[0-9][0-9_]*(?=([e.]|\'f(32|64)))`, LiteralNumberFloat, Push("float-suffix", "float-number")},
|
||||
{`0x[a-f0-9][a-f0-9_]*`, LiteralNumberHex, Push("int-suffix")},
|
||||
|
7
lexers/testdata/nim.actual
vendored
Normal file
7
lexers/testdata/nim.actual
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# -*- nim -*-
|
||||
import random
|
||||
proc randBool(): bool =
|
||||
randomize()
|
||||
result = rand(1).bool
|
||||
for _ in 0..5:
|
||||
echo randBool()
|
45
lexers/testdata/nim.expected
vendored
Normal file
45
lexers/testdata/nim.expected
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
[
|
||||
{"type":"Comment","value":"# -*- nim -*-"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"KeywordNamespace","value":"import"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"random"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Keyword","value":"proc "},
|
||||
{"type":"NameFunction","value":"randBool"},
|
||||
{"type":"Punctuation","value":"():"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordType","value":"bool"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"randomize"},
|
||||
{"type":"Punctuation","value":"()"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"result"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"rand"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralNumberInteger","value":"1"},
|
||||
{"type":"Punctuation","value":")."},
|
||||
{"type":"KeywordType","value":"bool"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Keyword","value":"for"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"_"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"OperatorWord","value":"in"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralNumberFloat","value":"0"},
|
||||
{"type":"Punctuation","value":".."},
|
||||
{"type":"LiteralNumberInteger","value":"5"},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"Text","value":"\n "},
|
||||
{"type":"Name","value":"echo"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Name","value":"randBool"},
|
||||
{"type":"Punctuation","value":"()"},
|
||||
{"type":"Text","value":"\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user