summaryrefslogtreecommitdiff
path: root/doc/0/grammar/peg.txt
blob: 1541da69ee59a721342f78fe69b3aa109f4fadd7 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Standard PEG notation

Stream       <- Unit ( Blank Unit )* !.


Unit         <- Blank* Datum

Blank        <- [\t-\r ] / Comment


Datum        <- OneDatum ( JoinChar? OneDatum )*

JoinChar     <- '.' / ':'


Comment      <- ';' ( SkipUnit / SkipLine )

SkipUnit     <- '~' Unit

SkipLine     <- (!'\n' .)* '\n'?


OneDatum     <- BareString / CladDatum


BareString   <- SpecBareChar ( BareChar / JoinChar )*
              / BareChar+

SpecBareChar <- '+' / '-' / JoinChar / DIGIT

BareChar     <- ALPHA / DIGIT
              / '!' / '$' / '%' / '&' / '*' / '+' / '-' / '/'
              / '<' / '=' / '>' / '?' / '^' / '_' / '~'


CladDatum    <- PipeStr / QuoteStr / HashExpr / QuoteExpr / List

PipeStr      <- '|' ( PipeStrChar / '\' StringEsc )* '|'
QuoteStr     <- '"' ( QuotStrChar / '\' StringEsc )* '"'
HashExpr     <- '#' HashExprs
QuoteExpr    <- "'" Datum / '`' Datum / ',' Datum
List         <- ParenList / SquareList / BraceList


PipeStrChar  <- (![|\\] .)
QuotStrChar  <- (!["\\] .)

StringEsc    <- '\' / '|' / '"' / ( HTAB / SP )* LF ( HTAB / SP )*
              / '0' / 'a' / 'b' / 't' / 'n' / 'v' / 'f' / 'r' / 'e'
              / 'x' HexByte* ';'
              / 'u' UnicodeSV ';'

HexByte      <- HEXDIG HEXDIG
UnicodeSV    <- HEXDIG+


HashExprs    <- '!' [\t ]* HBangLine '\n'?
              / '%' Label ( '%' / '=' Datum )
              / '\' BareString / CladDatum
              / Rune ( '\' BareString / CladDatum )?

HBangLine    <- HBChars+ [\t ]* ( HBChars+ )?
HBChars      <- (![\t\n ] .)
Label        <- HEXDIG+
Rune         <- ALPHA ( ALPHA / DIGIT )*


ParenList    <- '(' Unit* ')'
SquareList   <- '[' Unit* ']'
BraceList    <- '{' Unit* '}'


DIGIT        <- [0-9]
ALPHA        <- [a-zA-Z]
HEXDIG       <- [0-9a-fA-F]


# Keep this in sync line-for-line with the ZBNF grammar for easy
# comparison between the two.

# This file is meant to be compatible with:
# https://piumarta.com/software/peg

# Due to a quirk in the peg tool this file is used with, the grammar
# must not allow an empty stream.  Therefore, the Unit rule has its
# Datum declared as mandatory rather than optional.


# Local Variables:
# eval: (flyspell-mode -1)
# End: