Parser1.1.1
- Known subtypes:
- Known usages:
- All versions:
This parser can handle Lua files that consist of comments and key=value lines, where the key is a Lua identifier
and the value is a literal string, number, boolean, nil, or table. Expressions are not supported. At the top level
the key cannot be the identifier _ENV unless it is followed by a subscript expression, as in _ENV[key]=value.
An _ENV subscript like this allows the top-level to contain keys that are not Lua identifiers.
When parsing nested tables, tables using key/value syntax ({ [key] = value; … }) will be parsed as list elements
if the key is integral and equal to the next unused index, otherwise they will be treated as map entries. Be aware
that the order of keys is important here; { [0] = "a"; [1] = "b"; [2] = "c" } will be parsed as a list whereas
{ [2] = "c"; [1] = "b"; [0] = "a" } will be parsed as a map despite being equivalent Lua tables. See useDynamic
for details on the type used to represent nested tables.
When parsing _ENV[key]=value statements at the top-level, if the subscript key is an integral value and
useDynamic is true then it will be parsed as a list element in the same fashion as nested tables. However if
useDynamic is false then integral keys will not be treated any differently than other keys.
Lua values are mapped to Pkl values as follows:
| Lua type | Pkl type |
|---|---|
| nil | Null |
| boolean | Boolean |
| number | Number |
| string | String |
| table | Dynamic or Mapping/Listing depending on Parser.useDynamic |
Example
This is a sample Lua file that can be parsed with this Parser.
--[[
This file has a header comment.
]]
foo="bar"
count=2
-- line comment here
enable=true
frob=nil
ports={80, 443}
ips={
localhost = "127.0.0.1";
["example.com"] = "93.184.215.14";
}
_ENV[" "]="space"
Properties
-
expand_morelink
Determines what the parser produces when parsing Lua.
If
true(the default), the parse result is aDynamic, otherwise it's aMapping.For nested tables, if
trueevery nested table is aDynamic, otherwise a nested table will be aMappingif it contains key/value pairs, aListingif it contains elements, or it will throw an error if it contains both. Iffalsethen empty tables will be represented as emptyListings.If
useDynamicistrue, Lua keys named "default" will be shadowed by the built-inDynamic.defaultproperty. -
A parser for a strict subset of Lua.