-
Notifications
You must be signed in to change notification settings - Fork 772
/
pppars.fsy
60 lines (45 loc) · 2.23 KB
/
pppars.fsy
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
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
%{
open FSharp.Compiler.DiagnosticsLogger
let dummy = IfdefId("DUMMY")
let doNothing _ dflt=
dflt
let fail (ps : Internal.Utilities.Text.Parsing.IParseState) i e =
let f,t = ps.InputRange i
let m = mkSynRange f t
errorR(Error(e,m))
dummy
%}
%start start
%token <string> ID
%token OP_NOT OP_AND OP_OR LPAREN RPAREN PRELUDE EOF
%nonassoc RPAREN
%nonassoc PRELUDE
%left OP_OR
%left OP_AND
%left OP_NOT
%nonassoc LPAREN
%nonassoc ID
%type < LexerIfdefExpression > start
%%
start: Full { $1 }
Recover:
| error { doNothing parseState () }
Full:
| PRELUDE Expr EOF { $2 }
| Recover { fail parseState 1 (FSComp.SR.ppparsMissingToken("#if/#elif")) }
Expr:
| LPAREN Expr RPAREN { $2 }
| ID { IfdefId($1) }
| OP_NOT Expr { IfdefNot($2) }
| Expr OP_AND Expr { IfdefAnd($1,$3) }
| Expr OP_OR Expr { IfdefOr($1,$3) }
| OP_AND Recover { fail parseState 1 (FSComp.SR.ppparsUnexpectedToken("&&")) }
| OP_OR Recover { fail parseState 1 (FSComp.SR.ppparsUnexpectedToken("||")) }
| OP_NOT Recover { fail parseState 1 (FSComp.SR.ppparsUnexpectedToken("!")) }
| LPAREN error RPAREN { doNothing parseState dummy }
| LPAREN Expr Recover { fail parseState 3 (FSComp.SR.ppparsMissingToken(")")) }
| LPAREN Recover { fail parseState 2 (FSComp.SR.ppparsIncompleteExpression()) }
| RPAREN Recover { fail parseState 1 (FSComp.SR.ppparsUnexpectedToken(")")) }
| Expr Recover { fail parseState 2 (FSComp.SR.ppparsIncompleteExpression()) }
| EOF { fail parseState 1 (FSComp.SR.ppparsIncompleteExpression()) }