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

Commit ac889de

Browse files
authored
[#591] Allow application of single arguments without parentheses (#592)
* [#591] Allow application of single arguments… …without parentheses * remove parentheses from definitions of tags * remove sequence node * add test case
1 parent 5766e80 commit ac889de

File tree

9 files changed

+155
-152
lines changed

9 files changed

+155
-152
lines changed

common/enums.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum Prec {
2+
Group = -1,
23
SubtractionType = -1,
34
UnionType = 0,
45
Assignment = 1,
@@ -24,13 +25,14 @@ export enum Prec {
2425
Exponentiation = 12,
2526
Not = 13,
2627
InfixApplication = 14,
27-
PrefixApplication = 15,
28-
Application = 16,
29-
Term = 17,
30-
Pattern = 17,
31-
Access = 18,
32-
Pipeline = 19,
33-
ParametricTypeInstance = 20,
28+
Application = 15,
29+
Term = 16,
30+
Pattern = 16,
31+
Access = 17,
32+
Pipeline = 18,
33+
ParametricTypeInstance = 19,
34+
Argument = 20,
35+
Hole = 21,
3436
}
3537

3638
export enum Dialect {

common/patterns.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ export const tagged_pattern = <RuleName extends string>(
9191
) =>
9292
seq(
9393
field('name', alias($._identifier_without_operators, $.identifier)),
94-
'(',
9594
field('pattern', $._pattern),
96-
')',
9795
)
9896

9997
export const _literal_pattern = <RuleName extends string>(

common/terms.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ export const _term = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
1717
Prec.Term,
1818
choice(
1919
$.block,
20-
$.sequence,
2120
$.abstraction,
2221
$.application,
23-
$.prefix_application,
2422
$.infix_application,
2523
$._section,
2624
$.access,
@@ -50,10 +48,6 @@ export const _term = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
5048
export const block = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
5149
buildBlock($, field('term', $._term))
5250

53-
export const sequence = <RuleName extends string>(
54-
$: GrammarSymbols<RuleName>,
55-
) => seq('do', buildBlock($, field('term', $._term)))
56-
5751
export const export_ = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
5852
seq('export', field('declaration', $.assignment))
5953

@@ -95,7 +89,11 @@ export const instance = <RuleName extends string>(
9589

9690
export const argument = <RuleName extends string>(
9791
$: GrammarSymbols<RuleName>,
98-
) => prec.left(choice(field('placeholder', '?'), field('value', $._element)))
92+
) =>
93+
prec.left(
94+
Prec.Argument,
95+
choice(field('placeholder', '?'), field('value', $._element)),
96+
)
9997

10098
export const abstraction = <RuleName extends string>(
10199
$: GrammarSymbols<RuleName>,
@@ -112,19 +110,14 @@ export const abstraction = <RuleName extends string>(
112110
export const application = <RuleName extends string>(
113111
$: GrammarSymbols<RuleName>,
114112
) =>
115-
prec(
113+
prec.left(
116114
Prec.Application,
117-
seq(field('name', $._term), buildTuple($, $.argument, false, true)),
118-
)
119-
120-
export const prefix_application = <RuleName extends string>(
121-
$: GrammarSymbols<RuleName>,
122-
) =>
123-
prec.right(
124-
Prec.PrefixApplication,
125115
seq(
126-
field('name', alias($._operator, $.identifier)),
127-
field('value', $._term),
116+
field('name', $._term),
117+
choice(
118+
prec(Prec.Argument, buildTuple($, $.argument, false, true)),
119+
field('element', $._term),
120+
),
128121
),
129122
)
130123

@@ -483,7 +476,10 @@ export const type_hint = <RuleName extends string>(
483476
)
484477

485478
export const hole = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
486-
seq('?', field('name', alias($.identifier, $.identifier_pattern_name)))
479+
prec(
480+
Prec.Hole,
481+
seq('?', field('name', alias($.identifier, $.identifier_pattern_name))),
482+
)
487483

488484
export const _identifier_without_operators = () => IDENTIFIER
489485

@@ -494,4 +490,4 @@ export const identifier = <RuleName extends string>(
494490
) => choice($._operator, $._identifier_without_operators)
495491

496492
export const group = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
497-
seq('(', field('term', $._term), ')')
493+
prec(Prec.Group, seq('(', field('term', $._term), ')'))

common/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ export const tagged_type = <RuleName extends string>(
195195
'name',
196196
alias($._identifier_without_operators, $.identifier_pattern_name),
197197
),
198-
'(',
199198
field('type', $._type),
200-
')',
201199
),
202200
)
203201

@@ -236,7 +234,7 @@ export const refinement_type = <RuleName extends string>(
236234

237235
export const _predicate = <RuleName extends string>(
238236
$: GrammarSymbols<RuleName>,
239-
) => choice($.application, $.infix_application, $.prefix_application)
237+
) => choice($.application, $.infix_application)
240238

241239
export const type_group = <RuleName extends string>(
242240
$: GrammarSymbols<RuleName>,

tony/corpus/literals.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ decimal
3232
---
3333

3434
(program
35-
term: (prefix_application
35+
term: (application
3636
name: (identifier)
37-
value: (number))
38-
term: (prefix_application
37+
element: (number))
38+
term: (application
3939
name: (identifier)
40-
value: (number))
40+
element: (number))
4141
term: (number)
4242
term: (number)
4343
term: (number)
@@ -48,9 +48,9 @@ decimal
4848
term: (number)
4949
term: (number)
5050
term: (number)
51-
term: (prefix_application
51+
term: (application
5252
name: (identifier)
53-
value: (number)))
53+
element: (number)))
5454

5555
==================
5656
integer
@@ -68,9 +68,9 @@ integer
6868
---
6969

7070
(program
71-
term: (prefix_application
71+
term: (application
7272
name: (identifier)
73-
value: (number))
73+
element: (number))
7474
term: (number)
7575
term: (number)
7676
term: (number)

tony/corpus/patterns.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ struct pattern
6565
tagged struct pattern
6666
============================================
6767

68-
tag({ b: c :: Type }) = a
69-
tag({ b: c :: Type, d :: Type, ['e']: e :: Type, ...f :: Type = {} }) = a
68+
tag { b: c :: Type } = a
69+
tag { b: c :: Type, d :: Type, ['e']: e :: Type, ...f :: Type = {} } = a
7070

7171
---
7272

@@ -137,7 +137,7 @@ tuple pattern
137137
tagged tuple pattern
138138
============================================
139139

140-
tag((a, b :: Type, ...c)) = a
140+
tag (a, b :: Type, ...c) = a
141141

142142
---
143143

@@ -202,8 +202,8 @@ list pattern
202202
tagged list pattern
203203
============================================
204204

205-
tag([b :: Type, c :: Type]) = a
206-
tag([b :: Type, c :: Type, ...d :: Type = [1]]) = a
205+
tag [b :: Type, c :: Type] = a
206+
tag [b :: Type, c :: Type, ...d :: Type = [1]] = a
207207

208208
---
209209

@@ -247,16 +247,17 @@ tag([b :: Type, c :: Type, ...d :: Type = [1]]) = a
247247
tagged pattern
248248
============================================
249249

250-
tag(b) = a
250+
(tag b) = a
251251

252252
---
253253

254254
(program
255255
term: (assignment
256-
pattern: (tagged_pattern
257-
name: (identifier)
258-
pattern: (identifier_pattern
259-
name: (identifier_pattern_name)))
256+
pattern: (pattern_group
257+
pattern: (tagged_pattern
258+
name: (identifier)
259+
pattern: (identifier_pattern
260+
name: (identifier_pattern_name))))
260261
value: (identifier)))
261262

262263
============================================

0 commit comments

Comments
 (0)