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

Commit

Permalink
[#546] Remove colon from tags (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhue authored Mar 23, 2021
1 parent 0457c4e commit bacfae6
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 196 deletions.
3 changes: 2 additions & 1 deletion common/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ export const tagged_pattern = <RuleName extends string>(
$: GrammarSymbols<RuleName>,
) =>
seq(
':',
field('name', alias($._identifier_without_operators, $.identifier)),
'(',
field('pattern', $._pattern),
')',
)

export const _literal_pattern = <RuleName extends string>(
Expand Down
12 changes: 0 additions & 12 deletions common/terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const _term = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
$.tuple,
$.list,
$.list_comprehension,
$.tagged_value,
$.parametric_type_instance,
$.type_alias,
$.type_hint,
Expand Down Expand Up @@ -450,17 +449,6 @@ export const _element = <RuleName extends string>(
export const spread = <RuleName extends string>($: GrammarSymbols<RuleName>) =>
seq('...', field('value', $._term))

export const tagged_value = <RuleName extends string>(
$: GrammarSymbols<RuleName>,
) =>
prec.left(
seq(
':',
field('name', alias($._identifier_without_operators, $.identifier)),
field('value', $._term),
),
)

export const parametric_type_instance = <RuleName extends string>(
$: GrammarSymbols<RuleName>,
) =>
Expand Down
3 changes: 2 additions & 1 deletion common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ export const tagged_type = <RuleName extends string>(
prec(
Prec.TaggedType,
seq(
':',
field(
'name',
alias($._identifier_without_operators, $.identifier_pattern_name),
),
'(',
field('type', $._type),
')',
),
)

Expand Down
21 changes: 10 additions & 11 deletions tony/corpus/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct pattern
tagged struct pattern
============================================

:tag { b: c :: Type } = a
:tag { b: c :: Type, d :: Type, ['e']: e :: Type, ...f :: Type = {} } = a
tag({ b: c :: Type }) = a
tag({ b: c :: Type, d :: Type, ['e']: e :: Type, ...f :: Type = {} }) = a

---

Expand Down Expand Up @@ -137,7 +137,7 @@ tuple pattern
tagged tuple pattern
============================================

:tag (a, b :: Type, ...c) = a
tag((a, b :: Type, ...c)) = a

---

Expand Down Expand Up @@ -202,8 +202,8 @@ list pattern
tagged list pattern
============================================

:tag [b :: Type, c :: Type] = a
:tag [b :: Type, c :: Type, ...d :: Type = [1]] = a
tag([b :: Type, c :: Type]) = a
tag([b :: Type, c :: Type, ...d :: Type = [1]]) = a

---

Expand Down Expand Up @@ -247,17 +247,16 @@ tagged list pattern
tagged pattern
============================================

(:tag b) = a
tag(b) = a

---

(program
term: (assignment
pattern: (pattern_group
pattern: (tagged_pattern
name: (identifier)
pattern: (identifier_pattern
name: (identifier_pattern_name))))
pattern: (tagged_pattern
name: (identifier)
pattern: (identifier_pattern
name: (identifier_pattern_name)))
value: (identifier)))

============================================
Expand Down
136 changes: 19 additions & 117 deletions tony/corpus/terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ a<Type<Type, Type>, Type>(?, 1)
1 `a` -b()
a(...(a, b))

tag('String')
tag(1)
tag(())

---

(program
Expand Down Expand Up @@ -210,7 +214,19 @@ a(...(a, b))
value: (spread
value: (tuple
element: (identifier)
element: (identifier))))))
element: (identifier)))))
term: (application
name: (identifier)
element: (argument
value: (string)))
term: (application
name: (identifier)
element: (argument
value: (number)))
term: (application
name: (identifier)
element: (argument
value: (tuple))))

==================
prefix application
Expand Down Expand Up @@ -795,39 +811,6 @@ struct
member: (shorthand_member)
member: (shorthand_member)))

==================
tagged struct
==================

:tag {}
:tag { a, b }
:tag { ['a']: 1, ...b, c: 'str', d, e }

---

(program
term: (tagged_value
name: (identifier)
value: (struct))
term: (tagged_value
name: (identifier)
value: (struct
member: (shorthand_member)
member: (shorthand_member)))
term: (tagged_value
name: (identifier)
value: (struct
member: (member
key: (string)
value: (number))
member: (spread
value: (identifier))
member: (member
key: (shorthand_member_identifier)
value: (string))
member: (shorthand_member)
member: (shorthand_member))))

==================
tuple
==================
Expand All @@ -850,34 +833,6 @@ tuple
element: (number)
element: (number)))

==================
tagged tuple
==================

:tag ()
:tag (a, 1, 'str', ...x)
:tag (1,1)

---

(program
term: (tagged_value
name: (identifier)
value: (tuple))
term: (tagged_value
name: (identifier)
value: (tuple
element: (identifier)
element: (number)
element: (string)
element: (spread
value: (identifier))))
term: (tagged_value
name: (identifier)
value: (tuple
element: (number)
element: (number))))

==================
list
==================
Expand All @@ -904,38 +859,6 @@ list
right: (number))
element: (number)))

==================
tagged list
==================

:tag []
:tag [a, 1, ...b, 'str']
:tag [1,1..1,1]

---

(program
term: (tagged_value
name: (identifier)
value: (list))
term: (tagged_value
name: (identifier)
value: (list
element: (identifier)
element: (number)
element: (spread
value: (identifier))
element: (string)))
term: (tagged_value
name: (identifier)
value: (list
element: (number)
element: (infix_application
left: (number)
name: (identifier)
right: (number))
element: (number))))

==================
list comprehension
==================
Expand Down Expand Up @@ -1010,27 +933,6 @@ list comprehension
name: (identifier)
right: (number)))))

==================
tagged value
==================

:tag 'String'
:tag 1
:tag ()

---

(program
term: (tagged_value
name: (identifier)
value: (string))
term: (tagged_value
name: (identifier)
value: (number))
term: (tagged_value
name: (identifier)
value: (tuple)))

==================
parametric type instance
==================
Expand Down Expand Up @@ -1063,8 +965,8 @@ type alias
==================

type Type = Type
type Type = :tag Type
type Type = :tag Type | :tag ()
type Type = tag(Type)
type Type = tag(Type) | tag(())
type Type<T, U <: Num> = T => U
type GreaterThan<T>(x :: T) = [y :: T | y > x]

Expand Down
6 changes: 1 addition & 5 deletions tony/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import {
right_section,
spread,
struct,
tagged_value,
ternary,
tuple,
type_alias,
Expand Down Expand Up @@ -146,9 +145,7 @@ export = grammar({
[$.parametric_type_instance, $.infix_application],
[$.application, $.prefix_application, $.infix_application],
[$.application, $.infix_application],
[$.tagged_value, $.tagged_pattern],
[$.tagged_value, $.tagged_pattern, $.tagged_type],
[$.tagged_value, $.tagged_type],
[$.tagged_pattern, $.identifier],
[$.tagged_pattern, $.tagged_type],
[$.type_variable_declaration, $.parametric_type],
],
Expand Down Expand Up @@ -206,7 +203,6 @@ export = grammar({
list,
_element,
spread,
tagged_value,
parametric_type_instance,
type_alias,
type_hint,
Expand Down
Loading

0 comments on commit bacfae6

Please sign in to comment.