Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 9198cf0

Browse files
authored
Merge branch 'main' into feature/521-refactor-precedences
2 parents 0e50188 + ccd5ef8 commit 9198cf0

File tree

5 files changed

+125
-165
lines changed

5 files changed

+125
-165
lines changed

common/terms.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IDENTIFIER, OPERATOR } from './constants'
22
import {
3-
buildAbstractionBranch,
3+
buildAbstraction,
44
buildCompoundBlock,
55
buildGenericType,
66
buildList,
@@ -26,7 +26,6 @@ export const _simple_term = <RuleName extends string>(
2626
$.prefix_application,
2727
$.infix_application,
2828
$._section,
29-
// $.pipeline,
3029
$.access,
3130
alias($.simple_assignment, $.assignment),
3231
alias($.simple_export, $.export),
@@ -173,34 +172,11 @@ export const argument = <RuleName extends string>(
173172

174173
export const simple_abstraction = <RuleName extends string>(
175174
$: GrammarSymbols<RuleName>,
176-
) =>
177-
prec.left(
178-
Prec.PatternOrTerm,
179-
commaSep1(
180-
field('branch', alias($.simple_abstraction_branch, $.abstraction_branch)),
181-
),
182-
)
183-
184-
export const simple_abstraction_branch = <RuleName extends string>(
185-
$: GrammarSymbols<RuleName>,
186-
) => prec.left(buildAbstractionBranch($, $._simple_block))
175+
) => prec.left(buildAbstraction($, $._simple_block))
187176

188177
export const compound_abstraction = <RuleName extends string>(
189178
$: GrammarSymbols<RuleName>,
190-
) =>
191-
prec.left(
192-
Prec.PatternOrTerm,
193-
repeat1(
194-
field(
195-
'branch',
196-
alias($.compound_abstraction_branch, $.abstraction_branch),
197-
),
198-
),
199-
)
200-
201-
export const compound_abstraction_branch = <RuleName extends string>(
202-
$: GrammarSymbols<RuleName>,
203-
) => prec.left(buildAbstractionBranch($, $._compound_block))
179+
) => prec.left(buildAbstraction($, $._compound_block))
204180

205181
export const application = <RuleName extends string>(
206182
$: GrammarSymbols<RuleName>,

common/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const commaSep1 = sep1(',')
88

99
const commaSep2 = sep2(',')
1010

11-
export const buildAbstractionBranch = <RuleName extends string>(
11+
export const buildAbstraction = <RuleName extends string>(
1212
$: GrammarSymbols<RuleName>,
1313
blockType: Rule,
1414
) =>

tony/corpus/terms.txt

Lines changed: 121 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ abstraction
77
(a, b) => a
88
(a :: Type, b :: Type, 1, { c :: Type = 1 }) => a
99

10-
fib :=
11-
(0) =>
12-
0
13-
(1) => 1
14-
<a>(n :: a = 2) =>
15-
fib(n - 1) + fib(n - 2)
10+
fib := (a) =>
11+
0
12+
fib := (a) => 1
13+
fib := <a>(n :: a = 2) =>
14+
fib(n - 1) + fib(n - 2)
1615

1716
<a <: Type>(...a :: a) =>
1817
b := (c :: Type) =>
@@ -28,115 +27,115 @@ fn :: Number -> Number? -> Number := (a, b = 5) => a + b
2827

2928
(program
3029
term: (abstraction
31-
branch: (abstraction_branch
32-
element: (identifier_pattern
33-
name: (identifier_pattern_name))
34-
body: (block
35-
term: (identifier))))
30+
element: (identifier_pattern
31+
name: (identifier_pattern_name))
32+
body: (block
33+
term: (identifier)))
3634
term: (abstraction
37-
branch: (abstraction_branch
38-
element: (identifier_pattern
39-
name: (identifier_pattern_name))
35+
element: (identifier_pattern
36+
name: (identifier_pattern_name))
37+
element: (identifier_pattern
38+
name: (identifier_pattern_name))
39+
body: (block
40+
term: (identifier)))
41+
term: (abstraction
42+
element: (identifier_pattern
43+
name: (identifier_pattern_name)
44+
type: (parametric_type
45+
name: (type)))
46+
element: (identifier_pattern
47+
name: (identifier_pattern_name)
48+
type: (parametric_type
49+
name: (type)))
50+
element: (number)
51+
element: (destructuring_pattern
52+
pattern: (struct_pattern
53+
member: (shorthand_member_pattern
54+
name: (identifier_pattern_name)
55+
type: (parametric_type
56+
name: (type))
57+
default: (number))))
58+
body: (block
59+
term: (identifier)))
60+
term: (assignment
61+
pattern: (identifier_pattern
62+
name: (identifier_pattern_name))
63+
value: (abstraction
4064
element: (identifier_pattern
4165
name: (identifier_pattern_name))
4266
body: (block
43-
term: (identifier))))
44-
term: (abstraction
45-
branch: (abstraction_branch
46-
element: (identifier_pattern
47-
name: (identifier_pattern_name)
48-
type: (parametric_type
49-
name: (type)))
67+
term: (number))))
68+
term: (assignment
69+
pattern: (identifier_pattern
70+
name: (identifier_pattern_name))
71+
value: (abstraction
5072
element: (identifier_pattern
51-
name: (identifier_pattern_name)
52-
type: (parametric_type
53-
name: (type)))
54-
element: (number)
55-
element: (destructuring_pattern
56-
pattern: (struct_pattern
57-
member: (shorthand_member_pattern
58-
name: (identifier_pattern_name)
59-
type: (parametric_type
60-
name: (type))
61-
default: (number))))
73+
name: (identifier_pattern_name))
6274
body: (block
63-
term: (identifier))))
75+
term: (number))))
6476
term: (assignment
6577
pattern: (identifier_pattern
6678
name: (identifier_pattern_name))
6779
value: (abstraction
68-
branch: (abstraction_branch
69-
element: (number)
70-
body: (block
71-
term: (number)))
72-
branch: (abstraction_branch
73-
element: (number)
74-
body: (block
75-
term: (number)))
76-
branch: (abstraction_branch
77-
typeParameter: (type_variable_declaration
78-
name: (type_variable_declaration_name))
79-
element: (identifier_pattern
80-
name: (identifier_pattern_name)
81-
type: (type_variable)
82-
default: (number))
83-
body: (block
84-
term: (infix_application
85-
left: (application
86-
name: (identifier)
87-
element: (argument
88-
value: (infix_application
89-
left: (identifier)
90-
name: (identifier)
91-
right: (number))))
92-
name: (identifier)
93-
right: (application
94-
name: (identifier)
95-
element: (argument
96-
value: (infix_application
97-
left: (identifier)
98-
name: (identifier)
99-
right: (number)))))))))
100-
term: (abstraction
101-
branch: (abstraction_branch
10280
typeParameter: (type_variable_declaration
103-
name: (type_variable_declaration_name)
104-
constraint: (parametric_type
105-
name: (type)))
106-
rest: (identifier_pattern
81+
name: (type_variable_declaration_name))
82+
element: (identifier_pattern
10783
name: (identifier_pattern_name)
108-
type: (type_variable))
84+
type: (type_variable)
85+
default: (number))
10986
body: (block
110-
term: (assignment
111-
pattern: (identifier_pattern
112-
name: (identifier_pattern_name))
113-
value: (abstraction
114-
branch: (abstraction_branch
115-
element: (identifier_pattern
116-
name: (identifier_pattern_name)
117-
type: (parametric_type
118-
name: (type)))
119-
body: (block
120-
term: (identifier)))))
121-
term: (application
87+
term: (infix_application
88+
left: (application
89+
name: (identifier)
90+
element: (argument
91+
value: (infix_application
92+
left: (identifier)
93+
name: (identifier)
94+
right: (number))))
12295
name: (identifier)
123-
element: (argument
124-
value: (number))))))
96+
right: (application
97+
name: (identifier)
98+
element: (argument
99+
value: (infix_application
100+
left: (identifier)
101+
name: (identifier)
102+
right: (number))))))))
103+
term: (abstraction
104+
typeParameter: (type_variable_declaration
105+
name: (type_variable_declaration_name)
106+
constraint: (parametric_type
107+
name: (type)))
108+
rest: (identifier_pattern
109+
name: (identifier_pattern_name)
110+
type: (type_variable))
111+
body: (block
112+
term: (assignment
113+
pattern: (identifier_pattern
114+
name: (identifier_pattern_name))
115+
value: (abstraction
116+
element: (identifier_pattern
117+
name: (identifier_pattern_name)
118+
type: (parametric_type
119+
name: (type)))
120+
body: (block
121+
term: (identifier))))
122+
term: (application
123+
name: (identifier)
124+
element: (argument
125+
value: (number)))))
125126
term: (abstraction
126-
branch: (abstraction_branch
127127
body: (block
128-
term: (number))))
128+
term: (number)))
129129
term: (assignment
130130
pattern: (identifier_pattern
131131
name: (identifier_pattern_name))
132132
value: (abstraction
133-
branch: (abstraction_branch
134-
element: (identifier_pattern
135-
name: (identifier_pattern_name))
136-
element: (identifier_pattern
137-
name: (identifier_pattern_name))
138-
body: (block
139-
term: (identifier)))))
133+
element: (identifier_pattern
134+
name: (identifier_pattern_name))
135+
element: (identifier_pattern
136+
name: (identifier_pattern_name))
137+
body: (block
138+
term: (identifier))))
140139
term: (assignment
141140
pattern: (identifier_pattern
142141
name: (identifier_pattern_name)
@@ -150,17 +149,16 @@ fn :: Number -> Number? -> Number := (a, b = 5) => a + b
150149
to: (parametric_type
151150
name: (type)))))
152151
value: (abstraction
153-
branch: (abstraction_branch
154-
element: (identifier_pattern
155-
name: (identifier_pattern_name))
156-
element: (identifier_pattern
157-
name: (identifier_pattern_name)
158-
default: (number))
159-
body: (block
160-
term: (infix_application
161-
left: (identifier)
162-
name: (identifier)
163-
right: (identifier)))))))
152+
element: (identifier_pattern
153+
name: (identifier_pattern_name))
154+
element: (identifier_pattern
155+
name: (identifier_pattern_name)
156+
default: (number))
157+
body: (block
158+
term: (infix_application
159+
left: (identifier)
160+
name: (identifier)
161+
right: (identifier))))))
164162

165163
==================
166164
application
@@ -523,13 +521,12 @@ a := (a :: Type) =>
523521
pattern: (identifier_pattern
524522
name: (identifier_pattern_name))
525523
value: (abstraction
526-
branch: (abstraction_branch
527-
element: (identifier_pattern
528-
name: (identifier_pattern_name)
529-
type: (parametric_type
530-
name: (type)))
531-
body: (block
532-
term: (number))))))
524+
element: (identifier_pattern
525+
name: (identifier_pattern_name)
526+
type: (parametric_type
527+
name: (type)))
528+
body: (block
529+
term: (number)))))
533530

534531
==================
535532
export
@@ -552,12 +549,11 @@ export a := (x :: a) =>
552549
pattern: (identifier_pattern
553550
name: (identifier_pattern_name))
554551
value: (abstraction
555-
branch: (abstraction_branch
556-
element: (identifier_pattern
557-
name: (identifier_pattern_name)
558-
type: (type_variable))
559-
body: (block
560-
term: (number)))))))
552+
element: (identifier_pattern
553+
name: (identifier_pattern_name)
554+
type: (type_variable))
555+
body: (block
556+
term: (number))))))
561557

562558
==================
563559
return
@@ -574,13 +570,12 @@ return (a :: Type) =>
574570
value: (number))
575571
term: (return
576572
value: (abstraction
577-
branch: (abstraction_branch
578-
element: (identifier_pattern
579-
name: (identifier_pattern_name)
580-
type: (parametric_type
581-
name: (type)))
582-
body: (block
583-
term: (number))))))
573+
element: (identifier_pattern
574+
name: (identifier_pattern_name)
575+
type: (parametric_type
576+
name: (type)))
577+
body: (block
578+
term: (number)))))
584579

585580
==================
586581
if

tony/grammar.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
class_,
3232
class_member,
3333
compound_abstraction,
34-
compound_abstraction_branch,
3534
compound_assignment,
3635
compound_export,
3736
compound_if,
@@ -51,7 +50,6 @@ import {
5150
return_,
5251
right_section,
5352
simple_abstraction,
54-
simple_abstraction_branch,
5553
simple_assignment,
5654
simple_export,
5755
simple_if,
@@ -189,9 +187,7 @@ export = grammar({
189187
instance,
190188
argument,
191189
simple_abstraction,
192-
simple_abstraction_branch,
193190
compound_abstraction,
194-
compound_abstraction_branch,
195191
application,
196192
prefix_application,
197193
infix_application,

0 commit comments

Comments
 (0)