about summary refs log tree commit diff
path: root/src/fix-ng/fix.sdf
blob: 30f9306863c92d9dbd404dbaa2c0b93af216b984 (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
definition

module Main
imports Fix


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Top level syntax.

module Fix
imports Fix-Exprs Fix-Layout


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Expressions.

module Fix-Exprs
imports Fix-Lexicals URI
exports
  sorts Expr Bind Formal
  context-free syntax

    Id -> Expr {cons("Var")}

    Int -> Expr {cons("Int")}

    Str -> Expr {cons("Str")}

    Uri -> Expr {cons("Uri")}

    Path -> Expr {cons("Path")}

    "(" Expr ")" -> Expr {bracket}

    Expr Expr -> Expr {cons("Call"), left}

    "{" {Formal ","}* "}" ":" Expr -> Expr {cons("Function"), right}
    Id -> Formal {cons("NoDefFormal")}
    Id "?" Expr -> Formal {cons("DefFormal")}

    "assert" Expr ";" Expr -> Expr {cons("Assert"), right}

    "rec" "{" Binds "}" -> Expr {cons("Rec")}
    "let" "{" Binds "}" -> Expr {cons("LetRec")}
    "{" Binds "}" -> Expr {cons("Attrs")}

    Id "=" Expr -> Bind {cons("Bind")}
    {Bind ";"}* -> Binds
    Bind ";" -> BindSemi 
    BindSemi* -> Binds

    "[" ExprList "]" -> Expr {cons("List")}
    "" -> ExprList {cons("ExprNil")}
    Expr ExprList -> ExprList {cons("ExprCons")}

    Expr "." Id -> Expr {cons("Select")}

    "if" Expr "then" Expr "else" Expr -> Expr {cons("If")}

    Expr "==" Expr -> Expr {cons("OpEq"), non-assoc}
    Expr "!=" Expr -> Expr {cons("OpNEq"), non-assoc}

    "!" Expr -> Expr {cons("OpNot")}
    Expr "&&" Expr -> Expr {cons("OpAnd"), right}
    Expr "||" Expr -> Expr {cons("OpOr"), right}
    Expr "->" Expr -> Expr {cons("OpImpl"), right}

    Bool -> Expr {cons("Bool")}

  context-free priorities

    Expr "." Id -> Expr
  > Expr ExprList -> ExprList
  > Expr Expr -> Expr
  > "!" Expr -> Expr
  > Expr "==" Expr -> Expr
  > Expr "!=" Expr -> Expr
  > Expr "&&" Expr -> Expr
  > Expr "||" Expr -> Expr
  > Expr "->" Expr -> Expr
  > "assert" Expr ";" Expr -> Expr
  > "{" {Formal ","}* "}" ":" Expr -> Expr


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Lexical syntax.

module Fix-Lexicals
exports
  sorts Id Path
  lexical syntax
    [a-zA-Z\_][a-zA-Z0-9\_\']* -> Id
    "rec" -> Id {reject}
    "true" -> Id {reject}
    "false" -> Id {reject}
    "assert" -> Id {reject}

    [0-9]+ -> Int

    "\"" ~[\n\"]* "\"" -> Str

    PathComp ("/" PathComp)+ -> Path
    [a-zA-Z0-9\.\_\-\+]+ -> PathComp

    "true" -> Bool
    "false" -> Bool

  lexical restrictions
    Id -/- [a-zA-Z0-9\_\']
    Int -/- [0-9]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% URIs (RFC 2396, appendix A).

module URI
exports
  sorts Uri
  lexical syntax
    Uscheme ":" (Uhierpath | Uopaquepath) -> Uri

    (Unetpath | Uabspath) ("?" Uquery)? -> Uhierpath
    Uuricnoslash Uuric* -> Uopaquepath

    Uunreserved | Uescaped | [\;\?\:\@\&\=\+\$\,] -> Uuricnoslash

    "//" Uauthority Uabspath? -> Unetpath
    "/" Upathsegments -> Uabspath
    Urelsegment Uabspath? -> Urelpath

    (Uunreserved | Uescaped | [\;\@\&\=\+\$\,])+ -> Urelsegment

    Ualpha (Ualpha | Udigit | [\+\-\.])* -> Uscheme

    Userver | Uregname -> Uauthority

    (Uunreserved | Uescaped | [\$\,\;\:\@\&\=\+])+ -> Uregname

    ((Uuserinfo "@") Uhostport) -> Userver
    (Uunreserved | Uescaped | [\;\:\&\=\+\$\,])* -> Uuserinfo

    Uhost (":" Uport)? -> Uhostport
    Uhostname | UIPv4address -> Uhost
    (Udomainlabel ".")+ Utoplabel "."? -> Uhostname
    Ualphanum | Ualphanum (Ualphanum | "-")* Ualphanum -> Udomainlabel
    Ualpha | Ualpha (Ualphanum | "-")* Ualphanum -> Utoplabel
    Udigit+ "." Udigit+ "." Udigit+ "." Udigit+ -> UIPv4address
    Udigit* -> Uport

    Uabspath | Uopaquepart -> Upath
    Usegment ("/" Usegment)* -> Upathsegments
    Upchar* (";" Uparam)* -> Usegment
    Upchar* -> Uparam
    Uunreserved | Uescaped | [\:\@\&\=\+\$\,] -> Upchar

    Uuric* -> Uquery

    Uuric* -> Ufragment

    Ureserved | Uunreserved | Uescaped -> Uuric
    [\;\/\?\:\@\&\=\+\$\,] -> Ureserved
    Ualphanum | Umark -> Uunreserved
    [\-\_\.\!\~\*\'\(\)] -> Umark

    "%" Uhex Uhex -> Uescaped
    Udigit | [A-Fa-f] -> Uhex

    Ualpha | Udigit -> Ualphanum
    Ulowalpha | Uupalpha -> Ualpha

    [a-z] -> Ulowalpha
    [A-Z] -> Uupalpha
    [0-9] -> Udigit

  lexical restrictions
    Uri -/- [a-zA-Z0-9\-\_\.\!\~\*\'\(\)]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Layout.

module Fix-Layout
exports
  lexical syntax
    [\ \t\n] -> LAYOUT
    HashComment -> LAYOUT
    Comment -> LAYOUT
    "#" ~[\n]* [\n] -> HashComment
    "//" ~[\n]* [\n] -> HashComment
    "/*" ( ~[\*] | Asterisk )* "*/" -> Comment
    [\*] -> Asterisk
  lexical restrictions
    Asterisk -/- [\/]
  context-free restrictions
    LAYOUT? -/- [\ \t\n] | [\#]
  syntax
    HashComment <START> -> <START>