Skip to content

Commit c7c50d4

Browse files
authored
Merge pull request #110 from Keating950/master
Add highlighting for yield keyword from #[feature(generators)]
2 parents d045b04 + b100b7d commit c7c50d4

File tree

5 files changed

+70741
-69657
lines changed

5 files changed

+70741
-69657
lines changed

corpus/expressions.txt

+23
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,29 @@ a.map(|b: usize| b.push(c));
752752
(closure_parameters (parameter (identifier) (primitive_type)))
753753
(call_expression (field_expression (identifier) (field_identifier)) (arguments (identifier)))))))
754754

755+
===========================================
756+
Generators
757+
===========================================
758+
759+
move || {
760+
while i <= n {
761+
yield i;
762+
i += 1;
763+
}
764+
return;
765+
};
766+
767+
---
768+
769+
(source_file
770+
(closure_expression
771+
(closure_parameters)
772+
(block
773+
(while_expression (binary_expression (identifier) (identifier))
774+
(block (yield_expression (identifier))
775+
(compound_assignment_expr (identifier) (integer_literal))))
776+
(return_expression))))
777+
755778
===========================================
756779
Unsafe blocks
757780
===========================================

grammar.js

+6
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ module.exports = grammar({
842842
$.range_expression,
843843
$.call_expression,
844844
$.return_expression,
845+
$.yield_expression,
845846
$._literal,
846847
prec.left($.identifier),
847848
alias(choice(...primitive_types), $.identifier),
@@ -988,6 +989,11 @@ module.exports = grammar({
988989
prec(-1, 'return'),
989990
),
990991

992+
yield_expression: $ => choice(
993+
prec.left(seq('yield', $._expression)),
994+
prec(-1, 'yield'),
995+
),
996+
991997
call_expression: $ => prec(PREC.call, seq(
992998
field('function', $._expression),
993999
field('arguments', $.arguments)

src/grammar.json

+34
Original file line numberDiff line numberDiff line change
@@ -4665,6 +4665,10 @@
46654665
"type": "SYMBOL",
46664666
"name": "return_expression"
46674667
},
4668+
{
4669+
"type": "SYMBOL",
4670+
"name": "yield_expression"
4671+
},
46684672
{
46694673
"type": "SYMBOL",
46704674
"name": "_literal"
@@ -5742,6 +5746,36 @@
57425746
}
57435747
]
57445748
},
5749+
"yield_expression": {
5750+
"type": "CHOICE",
5751+
"members": [
5752+
{
5753+
"type": "PREC_LEFT",
5754+
"value": 0,
5755+
"content": {
5756+
"type": "SEQ",
5757+
"members": [
5758+
{
5759+
"type": "STRING",
5760+
"value": "yield"
5761+
},
5762+
{
5763+
"type": "SYMBOL",
5764+
"name": "_expression"
5765+
}
5766+
]
5767+
}
5768+
},
5769+
{
5770+
"type": "PREC",
5771+
"value": -1,
5772+
"content": {
5773+
"type": "STRING",
5774+
"value": "yield"
5775+
}
5776+
}
5777+
]
5778+
},
57455779
"call_expression": {
57465780
"type": "PREC",
57475781
"value": 14,

src/node-types.json

+23
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@
248248
{
249249
"type": "while_let_expression",
250250
"named": true
251+
},
252+
{
253+
"type": "yield_expression",
254+
"named": true
251255
}
252256
]
253257
},
@@ -4532,6 +4536,21 @@
45324536
]
45334537
}
45344538
},
4539+
{
4540+
"type": "yield_expression",
4541+
"named": true,
4542+
"fields": {},
4543+
"children": {
4544+
"multiple": false,
4545+
"required": false,
4546+
"types": [
4547+
{
4548+
"type": "_expression",
4549+
"named": true
4550+
}
4551+
]
4552+
}
4553+
},
45354554
{
45364555
"type": "!",
45374556
"named": false
@@ -4988,6 +5007,10 @@
49885007
"type": "while",
49895008
"named": false
49905009
},
5010+
{
5011+
"type": "yield",
5012+
"named": false
5013+
},
49915014
{
49925015
"type": "{",
49935016
"named": false

0 commit comments

Comments
 (0)