Idiomatically determine all the characters that can be used for symbols: Difference between revisions

→‎{{header|Lua}}: added Lua solution
(insert {{omit from}} Pascal)
(→‎{{header|Lua}}: added Lua solution)
Line 380:
Kotlin Identifier ignorable: [0][1][2][3][4][5][6][7][8][14][15][16][17][18][19][20][21][22][23][24][25][26][27][127][128]...
</pre>
 
=={{header|Lua}}==
From the 5.4 reference manual: "Names (also called identifiers) in Lua can be any string of Latin letters, Arabic-Indic digits, and underscores, not beginning with a digit and not being a reserved word."
<lang lua>function isValidIdentifier(id)
local reserved = {
["and"]=true, ["break"]=true, ["do"]=true, ["end"]=true, ["else"]=true, ["elseif"]=true, ["end"]=true,
["false"]=true, ["for"]=true, ["function"]=true, ["goto"]=true, ["if"]=true, ["in"]=true,
["local"]=true, ["nil"]=true, ["not"]=true, ["or"]=true, ["repeat"]=true, ["return"]=true,
["then"]=true, ["true"]=true, ["until"]=true, ["while"]=true }
return id:find("^[a-zA-Z_][a-zA-Z0-9_]*$") ~= nil and not reserved[id]
end
vfc, vsc = {}, {}
for i = 0, 255 do
local c = string.char(i)
if isValidIdentifier(c) then vfc[#vfc+1]=c end
if isValidIdentifier("_"..c) then vsc[#vsc+1]=c end
end
print("Valid First Characters: " .. table.concat(vfc))
print("Valid Subsequent Characters: " .. table.concat(vsc))</lang>
{{out}}
<pre>Valid First Characters: ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
Valid Subsequent Characters: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Anonymous user