summaryrefslogtreecommitdiff
path: root/spec/syntax.peg
diff options
context:
space:
mode:
Diffstat (limited to 'spec/syntax.peg')
-rw-r--r--spec/syntax.peg63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/syntax.peg b/spec/syntax.peg
new file mode 100644
index 0000000..97b9632
--- /dev/null
+++ b/spec/syntax.peg
@@ -0,0 +1,63 @@
+Unit <- Blank* ( Datum Blank? )?
+
+
+Blank <- ' ' / '\t' / '\n' / Comment
+
+Datum <- OneDatum ( JoinChar? OneDatum )*
+
+JoinChar <- '.' / ':'
+
+
+Comment <- ';' ( SkipUnit / SkipLine )
+
+SkipUnit <- '~' Unit
+
+SkipLine <- (!'\n' .)* '\n'?
+
+
+OneDatum <- BareString / CladDatum
+
+
+BareString <- ( '.' / '+' / '-' / DIGIT ) ( BareChar / '.' )*
+ / BareChar+
+
+CladDatum <- PipeStr / QuoteStr / HashExpr / QuoteExpr / List
+
+PipeStr <- '|' ( PipeStrChar / '\' StringEsc )* '|'
+QuoteStr <- '"' ( QuotStrChar / '\' StringEsc )* '"'
+HashExpr <- '#' ( RuneExpr / LabelExpr / HashDatum )
+QuoteExpr <- "'" Datum / '`' Datum / ',' Datum
+List <- ParenList / SquareList / BraceList
+
+BareChar <- ALPHA / DIGIT
+ / '!' / '$' / '%' / '*' / '+'
+ / '-' / '/' / '<' / '=' / '>'
+ / '?' / '@' / '^' / '_' / '~'
+
+PipeStrChar <- (![|\\] .)
+QuotStrChar <- (!["\\] .)
+
+StringEsc <- '\' / '|' / '"' / ( HTAB / SP )* LF ( HTAB / SP )*
+ / 'a' / 'b' / 't' / 'n' / 'v' / 'f' / 'r' / 'e'
+ / 'x' HexByte+ ';'
+ / 'u' UnicodeSV ';'
+
+HexByte <- HEXDIG HEXDIG
+UnicodeSV <- HEXDIG+
+
+RuneExpr <- Rune [ '\' BareString / CladDatum ]
+LabelExpr <- '%' Label ( '%' / '=' Datum )
+HashDatum <- '\' BareString / CladDatum
+
+Rune <- ALPHA ( ALPHA / DIGIT )*
+Label <- HEXDIG+
+
+ParenList <- '(' ListBody ')'
+SquareList <- '[' ListBody ']'
+BraceList <- '{' ListBody '}'
+
+ListBody <- Unit* [ Blank* '&' Unit ] Blank*
+
+DIGIT <- [0-9]
+ALPHA <- [a-zA-Z]
+HEXDIG <- [0-9a-fA-F]