mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib/lua: add isKeyword
and isIdentifier
Allow testing whether a string is a valid lua identifier or a reserved keyword.
This commit is contained in:
parent
b64ee08d6b
commit
01cf43dbaa
3 changed files with 118 additions and 3 deletions
|
@ -1,6 +1,37 @@
|
|||
{ lib }:
|
||||
with lib;
|
||||
rec {
|
||||
# Whether the string is a reserved keyword in lua
|
||||
isKeyword =
|
||||
s:
|
||||
elem s [
|
||||
"and"
|
||||
"break"
|
||||
"do"
|
||||
"else"
|
||||
"elseif"
|
||||
"end"
|
||||
"false"
|
||||
"for"
|
||||
"function"
|
||||
"if"
|
||||
"in"
|
||||
"local"
|
||||
"nil"
|
||||
"not"
|
||||
"or"
|
||||
"repeat"
|
||||
"return"
|
||||
"then"
|
||||
"true"
|
||||
"until"
|
||||
"while"
|
||||
];
|
||||
|
||||
# Valid lua identifiers are not reserved keywords, do not start with a digit,
|
||||
# and contain only letters, digits, and underscores.
|
||||
isIdentifier = s: !(isKeyword s) && (match "[A-Za-z_][0-9A-Za-z_]*" s) == [ ];
|
||||
|
||||
# Black functional magic that converts a bunch of different Nix types to their
|
||||
# lua equivalents!
|
||||
toLuaObject =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue