diff --git a/lexers/n/nim.go b/lexers/n/nim.go index eee5cab..1f7ec79 100644 --- a/lexers/n/nim.go +++ b/lexers/n/nim.go @@ -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")}, diff --git a/lexers/testdata/nim.actual b/lexers/testdata/nim.actual new file mode 100644 index 0000000..1ce1125 --- /dev/null +++ b/lexers/testdata/nim.actual @@ -0,0 +1,7 @@ +# -*- nim -*- +import random +proc randBool(): bool = + randomize() + result = rand(1).bool +for _ in 0..5: + echo randBool() diff --git a/lexers/testdata/nim.expected b/lexers/testdata/nim.expected new file mode 100644 index 0000000..b86717d --- /dev/null +++ b/lexers/testdata/nim.expected @@ -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"} +]