Skip to content

Commit

Permalink
Fix Type parameters and type arguments (#81)
Browse files Browse the repository at this point in the history
* Const_parameter should receive any type

* Type_argument should accept blocks to support expression on const generics
  • Loading branch information
GrayJack committed Apr 6, 2020
1 parent ec25830 commit 3e5ec5a
Show file tree
Hide file tree
Showing 5 changed files with 55,467 additions and 55,295 deletions.
71 changes: 63 additions & 8 deletions corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ fn foo(x: impl FnOnce() -> result::Result<T, E>) {}

fn foo(#[attr] x: i32, #[attr] x: i64) {}

fn accumulate(self) -> Machine<{State::Accumulate}> {}

---

(source_file
Expand Down Expand Up @@ -162,6 +164,19 @@ fn foo(#[attr] x: i32, #[attr] x: i64) {}
(parameter
pattern: (identifier)
type: (primitive_type)))
body: (block))
(function_item
name: (identifier)
parameters: (parameters
(self_parameter
(self)))
return_type: (generic_type
type: (type_identifier)
type_arguments: (type_arguments
(block
(scoped_identifier
path: (identifier)
name: (identifier)))))
body: (block)))

============================================
Expand Down Expand Up @@ -445,7 +460,7 @@ struct D<const SIZE: usize> {}
type_parameters: (type_parameters
(const_parameter
name: (identifier)
type: (type_identifier)))
type: (primitive_type)))
body: (field_declaration_list)))

============================================
Expand Down Expand Up @@ -562,7 +577,7 @@ pub fn uninit_array<const LEN: usize>() -> [Self; LEN] {}
type_parameters: (type_parameters
(const_parameter
name: (identifier)
type: (type_identifier)))
type: (primitive_type)))
parameters: (parameters)
return_type: (array_type
element: (type_identifier)
Expand Down Expand Up @@ -854,15 +869,55 @@ impl Person {
fn talk_mut(&'a mut self) {}
}

impl Machine<{State::Init}> {}

---

(source_file
(impl_item (type_identifier) (declaration_list
(const_item (identifier) (primitive_type) (integer_literal))
(function_item (identifier) (parameters (self_parameter (self))) (block))
(function_item (identifier) (parameters (self_parameter (mutable_specifier) (self))) (block))
(function_item (identifier) (parameters (self_parameter (self))) (block))
(function_item (identifier) (parameters (self_parameter (lifetime (identifier)) (mutable_specifier) (self))) (block)))))
(impl_item
type: (type_identifier)
body: (declaration_list
(const_item
name: (identifier)
type: (primitive_type)
value: (integer_literal))
(function_item
name: (identifier)
parameters: (parameters
(self_parameter
(self)))
body: (block))
(function_item
name: (identifier)
parameters: (parameters
(self_parameter
(mutable_specifier)
(self)))
body: (block))
(function_item
name: (identifier)
parameters: (parameters
(self_parameter
(self)))
body: (block))
(function_item
name: (identifier)
parameters: (parameters
(self_parameter
(lifetime
(identifier))
(mutable_specifier)
(self)))
body: (block))))
(impl_item
type: (generic_type
type: (type_identifier)
type_arguments: (type_arguments
(block
(scoped_identifier
path: (identifier)
name: (identifier)))))
body: (declaration_list)))

===========================================
Trait impls
Expand Down
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ module.exports = grammar({
'const',
field('name', $.identifier),
':',
field('type', $._type_identifier),
field('type', $._type),
),

constrained_type_parameter: $ => seq(
Expand Down Expand Up @@ -778,6 +778,7 @@ module.exports = grammar({
$.type_binding,
$.lifetime,
$._literal,
$.block,
)),
optional(','),
'>'
Expand Down
12 changes: 10 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
},
{
"type": "PATTERN",
"value": "[\\/_\\-=->,;:::!=?.@*=\\/=&=#%=^=+<>|~]+"
"value": "[/_\\-=->,;:::!=?.@*=/=&=#%=^=+<>|~]+"
},
{
"type": "STRING",
Expand Down Expand Up @@ -2975,7 +2975,7 @@
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
"name": "_type"
}
}
]
Expand Down Expand Up @@ -4345,6 +4345,10 @@
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
Expand Down Expand Up @@ -4375,6 +4379,10 @@
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "block"
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@
"required": true,
"types": [
{
"type": "type_identifier",
"type": "_type",
"named": true
}
]
Expand Down Expand Up @@ -3835,6 +3835,10 @@
"type": "_type",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "lifetime",
"named": true
Expand Down

0 comments on commit 3e5ec5a

Please sign in to comment.