-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec3.lua
More file actions
76 lines (67 loc) · 1.82 KB
/
spec3.lua
File metadata and controls
76 lines (67 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local lpeg = require "lpeg"
local re = require "re"
local gram = re.compile[=[
gram <- {| lines {:_trailing: {.*} :} |}
lines <- line*
line <- {| keyvalue |} %nl*
varname <- [a-zA-Z_] [_a-zA-Z0-9]*
value <- string
keyvalue <- {:varname: {varname} :} anyspace '=' anyspace anyvalue
anyvalue <- ( stringvalue / tablevalue ) %nl?
stringvalue <- {:value: string :}
string <- string1 / string2 / string3
string1 <- {| '"' { [^"]* } '"' {:_type: '' -> "string1" :} |}
string2 <- {| "'" { [^']* } "'" {:_type: '' -> "string2" :} |}
string3 <- {| {:_type: '' -> "string3" :} "[[" %nl? { [^]]* } "]]" |}
tablevalue <- {:value: table :}
table <- {| {:_type: '' -> "table" :} "{" %nl? anyspace ( tableitem ("," %nl? anyspace tableitem )* ) / ( tableitem ",") "}" |}
tableitem <- tablekeyvalue / tablequickvalue
tablequickvalue <- {| stringvalue |}
tablekeyvalue <- {| ( {:tkey: anytablekeys :} anyspace "=" anyspace {:tvalue: anyvalue :} anyspace) |}
anytablekeys <- {| ("[" anyspace ( string1 / string2 ) anyspace "]") / { varname } {:_type: '' -> "likevarname" :} |}
anyspace <- (' ' )*
somespaces <- (' ' / %nl )+
name <- [^ <>()=,]+
]=]
local function parse(data)
return gram:match(data)
end
local data
--data = [[package = "luafilesystem"]]
--data = [[package = 'luafilesystem']]
--data = "package = [[luafilesystem]]"
data = [[
package = "luafilesystem"
version = "scm-1"
source = {
url = "git://github.com/keplerproject/luafilesystem"
}
]]
data = [=[
package = "luafilesystem"
version = "scm-1"
foo = 'F o o'
bar = [[
BAR
blah blah
]]
tab1 = {
["foo"] = "FOO",
bar = "BAR"
}
]=]
data = [=[
build = {
type = "builtin",
modules = {
lfs = "src/lfs.c"
},
copy_directories = {
"doc",
"tests"
}
}
]=]
local result = parse(data)
local tprint = require"tprint"
print(tprint(result, {inline=false}))