Skip to content

Commit

Permalink
TOML: new PEG based parser
Browse files Browse the repository at this point in the history
  • Loading branch information
masatake committed Aug 8, 2024
1 parent 213950a commit 718457c
Show file tree
Hide file tree
Showing 14 changed files with 674 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SystemdUnit u/unit RequiredBy on referred in Required
SystemdUnit u/unit Requires on referred in Requires key
SystemdUnit u/unit WantedBy on referred in WantedBy key
SystemdUnit u/unit Wants on referred in Wants key
TOML k/key chainElt off (EXPERIMENTAL)used as an element in a key name chain like a.b.c
Terraform v/variable assigned on assigned in Variable Definitions (.tfvars) files
Tex e/environment used off environment usage introduced by \begin{MyEnv}
Tex i/xinput bibliography on bibliography (.bib) file
Expand Down Expand Up @@ -264,6 +265,7 @@ SystemdUnit u/unit RequiredBy on referred in Required
SystemdUnit u/unit Requires on referred in Requires key
SystemdUnit u/unit WantedBy on referred in WantedBy key
SystemdUnit u/unit Wants on referred in Wants key
TOML k/key chainElt off (EXPERIMENTAL)used as an element in a key name chain like a.b.c
Terraform v/variable assigned on assigned in Variable Definitions (.tfvars) files
Tex e/environment used off environment usage introduced by \begin{MyEnv}
Tex i/xinput bibliography on bibliography (.bib) file
Expand Down
2 changes: 2 additions & 0 deletions Units/parser-toml.r/simple.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+K{nth}{end}{line}
34 changes: 34 additions & 0 deletions Units/parser-toml.r/simple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
title input.toml /^title = "TOML Example"$/;" qkey line:5
dog."tater.man" input.toml /^[dog."tater.man"]$/;" table line:7 end:10
type.name input.toml /^type.name = "pug"$/;" qkey line:8 table:dog."tater.man"
x input.toml /^x = 1$/;" qkey line:9 table:dog."tater.man"
owner input.toml /^[owner]$/;" table line:11 end:14
name input.toml /^name = "Tom Preston-Werner"$/;" qkey line:12 table:owner
dob input.toml /^dob = 1979-05-27T07:32:00-08:00 # First class dates$/;" qkey line:13 table:owner
database input.toml /^[database]$/;" table line:15 end:20
server input.toml /^server = "192.168.1.1"$/;" qkey line:16 table:database
ports input.toml /^ports = [ 8001, 8001, 8002 ]$/;" qkey line:17 table:database
connection_max input.toml /^connection_max = 5000$/;" qkey line:18 table:database
enabled input.toml /^enabled = true$/;" qkey line:19 table:database
servers input.toml /^[servers]$/;" table line:21 end:23
servers.alpha input.toml /^ [servers.alpha]$/;" table line:24 end:27
ip input.toml /^ ip = "10.0.0.1"$/;" qkey line:25 table:servers.alpha
dc input.toml /^ dc = "eqdc10"$/;" qkey line:26 table:servers.alpha
servers.beta input.toml /^ [servers.beta]$/;" table line:28 end:31
ip input.toml /^ ip = "10.0.0.2"$/;" qkey line:29 table:servers.beta
dc input.toml /^ dc = "eqdc10"$/;" qkey line:30 table:servers.beta
clients input.toml /^[clients]$/;" table line:32 end:40
data input.toml /^data = [ ["gamma", "delta"], [1, 2] ]$/;" qkey line:33 table:clients
hosts input.toml /^hosts = [$/;" qkey line:36 table:clients
products input.toml /^[[products]] # 0$/;" arraytable line:41 end:44 nth:0
name input.toml /^name = "Hammer"$/;" qkey line:42 arraytable:products
sku input.toml /^sku = 738594937$/;" qkey line:43 arraytable:products
products input.toml /^[[products]] # 1$/;" arraytable line:45 end:46 nth:1
products input.toml /^[[products]] # 2$/;" arraytable line:47 end:50 nth:2
name input.toml /^name = "Nail"$/;" qkey line:48 arraytable:products
sku input.toml /^sku = 284758393$/;" qkey line:49 arraytable:products
color input.toml /^color = "gray"$/;" qkey line:50 arraytable:products
x input-0.toml /^[x]$/;" table line:1 end:4
y input-0.toml /^y = 1$/;" qkey line:2 table:x
"" input-0.toml /^"" = 2$/;" qkey line:3 table:x
'' input-0.toml /^'' = 3$/;" qkey line:4 table:x
1 change: 1 addition & 0 deletions Units/parser-toml.r/simple.d/features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packcc
4 changes: 4 additions & 0 deletions Units/parser-toml.r/simple.d/input-0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[x]
y = 1
"" = 2
'' = 3
50 changes: 50 additions & 0 deletions Units/parser-toml.r/simple.d/input.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Taken from https://toml.io/en/v0.5.0#example

# This is a TOML document.

title = "TOML Example"

[dog."tater.man"]
type.name = "pug"
x = 1

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"

[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]

[[products]] # 0
name = "Hammer"
sku = 738594937

[[products]] # 1

[[products]] # 2
name = "Nail"
sku = 284758393
color = "gray"
2 changes: 2 additions & 0 deletions docs/news/HEAD.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Parser related changes
New parsers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* TOML *peg/packcc*

Changes about parser specific kinds, roles, fields, and extras
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
VarlinkParser, \
KotlinParser, \
ThriftParser, \
ElmParser
ElmParser, \
TomlParser
#else
#define PEG_PARSER_LIST
#endif
Expand Down
1 change: 1 addition & 0 deletions peg/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ varlink.[ch]
kotlin.[ch]
thrift.[ch]
elm.[ch]
toml.[ch]

*.pego
Loading

0 comments on commit 718457c

Please sign in to comment.