Quote Lua keywords in table keys

Keywords are not valid as unquoted keys, thus must be quoted
This commit is contained in:
Kim Alvefur 2023-07-31 08:03:10 +02:00
parent 21fda2eb3d
commit c8919f20da

View File

@ -90,6 +90,16 @@ func (le *luaEncoder) encodeArray(writer io.Writer, node *yaml.Node) error {
} }
func needsQuoting(s string) bool { func needsQuoting(s string) bool {
// known keywords as of Lua 5.4
switch s {
case "do", "and", "else", "break",
"if", "end", "goto", "false",
"in", "for", "then", "local",
"or", "nil", "true", "until",
"elseif", "function", "not",
"repeat", "return", "while":
return true
}
// [%a_][%w_]* // [%a_][%w_]*
for i, c := range s { for i, c := range s {
if i == 0 { if i == 0 {