Skip to content

Commit fa0a700

Browse files
committed
Add fixity declarations
1 parent 052dc9c commit fa0a700

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

lexer.mll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ rule token = parse
269269
| "fun" { FUN }
270270
| "if" { IF }
271271
| "in" { IN }
272+
| "infix" { INFIX }
273+
| "infixl" { INFIXL }
274+
| "infixr" { INFIXR }
272275
| "..." { ELLIPSIS }
273276
| "let" { LET }
274277
| "||" { LOGICAL_OR }

parser.mly

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let parse_error s = raise (Source.Error (Source.nowhere_region, s))
3939
%token IMPORT
4040
%token WRAP_OP UNWRAP_OP
4141
%token ROLL_OP UNROLL_OP
42+
%token INFIX INFIXL INFIXR
4243

4344
%token EOF
4445

@@ -227,6 +228,37 @@ opttypdef :
227228
{ Some (typE($2)@@ati 2) }
228229
;
229230

231+
syms :
232+
| sym
233+
{ [$1] }
234+
| syms sym
235+
{ $2::$1 }
236+
;
237+
optsyms :
238+
|
239+
{ [] }
240+
| syms
241+
{ $1 }
242+
;
243+
infix :
244+
| INFIX
245+
{ () }
246+
| INFIXL
247+
{ () }
248+
| INFIXR
249+
{ () }
250+
;
251+
optprecedence :
252+
|
253+
{ 0@@at() }
254+
| NUM
255+
{ $1@@at() }
256+
;
257+
fixitydec :
258+
| infix optprecedence optsyms
259+
{ EmptyD@@at() }
260+
;
261+
230262
atdec :
231263
| name typparamlist COLON typ
232264
{ VarD($1, funT($2, $4, Pure@@ati 2)@@span[ati 2; ati 4])@@at() }
@@ -249,6 +281,8 @@ atdec :
249281
{ InclD($2)@@at() }
250282
| LET bind IN typ
251283
{ InclD(letT($2, $4)@@at())@@at() }
284+
| fixitydec
285+
{ $1 }
252286
/*
253287
| LPAR dec RPAR
254288
{ $2 }
@@ -453,6 +487,8 @@ atbind :
453487
{ InclB(letE($2, $4)@@at())@@at() }
454488
| IMPORT TEXT
455489
{ InclB(ImportE($2@@ati 2)@@at())@@at() }
490+
| fixitydec
491+
{ EmptyB@@at() }
456492
/*
457493
| LPAR bind RPAR
458494
{ $2 }

prelude/index.1mls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
local import "./primitives"
22

3+
infixl 8 * / %
4+
5+
infixl 7 + -
6+
7+
infixr 6 :: ++
8+
9+
infix 5 < > <= >= == <>
10+
11+
infixl 4 << >>
12+
13+
infixl 3 |>
14+
infixr 3 <|
15+
16+
;;
17+
318
Alt: {
419
type t _ _
520
inl 'a 'b: a -> t a b

0 commit comments

Comments
 (0)