-
Notifications
You must be signed in to change notification settings - Fork 125
/
mouse.trx
104 lines (77 loc) · 4.03 KB
/
mouse.trx
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
92
93
94
95
96
97
98
99
100
101
102
103
104
(*
Copyright © 2011 MLstate
This file is part of Opa.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*)
## Author: Adam Koprowski
## A TRX grammar for PEG grammar's in the Mouse format.
## Mouse is a PEG tool by Roman Redziejowski
## http://www.romanredz.se/freesoft.htm
## this grammar was (manuallly) transcribed from grammar.mouse
## (i.e. grammar.peg coming in the distribution of Mouse)
## after preforming certain simplifications on the grammar.
{{
open MouseAst
}}
/** Grammar **/
+Grammar : {MouseAst.mouse_grammar} <- Space (&. Rule)*:grammar EOT {{ grammar : mouse_grammar }}
/** Rule **/
Rule <- Name:name EQUAL RuleRhs:rhs DiagName?:desc SEMI {{ Rule(name, rhs, desc) }}
/** right-hand side **/
RuleRhs <- Sequence:seq Actions (SLASH Sequence:seq Actions {{seq}})*:seqs {{ seq::seqs }}
Choice <- Sequence:seq (SLASH Sequence:seq {{seq}})*:seqs {{ seq::seqs }}
Sequence <- Prefixed+
Prefixed <- PREFIX:prefix Space Primary:item SUFFIX:suffix Space {{ (prefix, item, suffix) }}
Primary <- / Name:name {{ Call name }}
/ LPAREN Choice:exp RPAREN {{ Parens exp }}
/ ANY {{ Any }}
/ StringLit:lit {{ Literal lit }}
/ Range:range {{ let (c1, c2) = range in Range(c1, c2) }}
/ CharClass:cc {{ CharClass cc }}
Actions <- OnSucc OnFail $
OnSucc <- (LWING AND? Name? RWING)? $
OnFail <- (TILDA LWING Name? RWING)? $
Name <- (Letter (Letter / Digit)* $_) Space {{ __1 }}
DiagName <- "<" ((!">" Char)+ $_) ">" Space {{ __2 }}
StringLit <- [\"] ((![\"] Char)+ $_):lit [\"] Space {{ lit }}
CharClass <- "[" (!"]" Char)+:chars "]" Space {{ chars }}
Range <- "[" Char:c1 "-" Char:c2 "]" Space {{ (c1, c2) }}
Char <- Escape
/ ![\r\n\\] .
Escape <- "\\u" (HexDigit HexDigit HexDigit HexDigit $_):hex
{{ let s = Base.String.from_hex hex in
assert(String.length s = 2 && Char.code (String.get s 0) = 0);
String.get s 1
}}
/ "\\t" {{ '\t' }}
/ "\\n" {{ '\n' }}
/ "\\r" {{ '\r' }}
/ !"\\u""\\" .:c {{ c }}
Letter <- [a-z] / [A-Z]
Digit <- [0-9]
HexDigit <- [0-9] / [a-f] / [A-F]
PREFIX <- [&] {{ `AND }}
/ [!] {{ `NOT }}
/ "" {{ `NORMAL }}
SUFFIX <- [?] {{ `OPTION }}
/ [*] {{ `STAR }}
/ [+] {{ `PLUS }}
/ "" {{ `NORMAL }}
EQUAL <- "=" Space {{ __1 }}
SEMI <- ";" Space {{ __1 }}
SLASH <- "/" Space {{ __1 }}
AND <- "&" Space {{ __1 }}
LPAREN <- "(" Space {{ __1 }}
RPAREN <- ")" Space {{ __1 }}
LWING <- "{" Space {{ __1 }}
RWING <- "}" Space {{ __1 }}
TILDA <- "~" Space {{ __1 }}
ANY <- "_" Space {{ __1 }}
Space <- ([ \r\n\t] $ / Comment)* $
Comment <- "//" (!EOL .)* EOL $
/* end of line */
EOL <- [\r\n] $ / !. $
/* end of text */
EOT <- !. $