diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-30 13:18:41 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-30 13:18:41 +0100 |
commit | 51b18ee2f1c3c9f7ea58c5f00b451e683048f618 (patch) | |
tree | 1152a079401b2d34bcc903f7935fe1aff0b7b3db /xtask/src | |
parent | 9042009b7f1ba0f85e892ac5184fa4542d0c10f5 (diff) | |
parent | 02cac962e133d420485bc7b64698902dcc26a5e7 (diff) |
Merge #5587
5587: Finish use grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/ast_src.rs | 2 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 35 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 27 |
3 files changed, 50 insertions, 14 deletions
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 083727c5c..3a58217c4 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -100,7 +100,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
100 | "RET_TYPE", | 100 | "RET_TYPE", |
101 | "EXTERN_CRATE", | 101 | "EXTERN_CRATE", |
102 | "MODULE", | 102 | "MODULE", |
103 | "USE_ITEM", | 103 | "USE", |
104 | "STATIC_DEF", | 104 | "STATIC_DEF", |
105 | "CONST_DEF", | 105 | "CONST_DEF", |
106 | "TRAIT_DEF", | 106 | "TRAIT_DEF", |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 9b49712c1..c77fc8a8d 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -543,6 +543,10 @@ fn lower_enum(grammar: &Grammar, rule: &Rule) -> Option<Vec<String>> { | |||
543 | } | 543 | } |
544 | 544 | ||
545 | fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { | 545 | fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { |
546 | if lower_comma_list(acc, grammar, rule) { | ||
547 | return; | ||
548 | } | ||
549 | |||
546 | match rule { | 550 | match rule { |
547 | Rule::Node(node) => { | 551 | Rule::Node(node) => { |
548 | let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand }; | 552 | let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand }; |
@@ -595,6 +599,37 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { | |||
595 | } | 599 | } |
596 | } | 600 | } |
597 | 601 | ||
602 | // (T (',' T)* ','?)? | ||
603 | fn lower_comma_list(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) -> bool { | ||
604 | let rule = match rule { | ||
605 | Rule::Opt(it) => it, | ||
606 | _ => return false, | ||
607 | }; | ||
608 | let rule = match &**rule { | ||
609 | Rule::Seq(it) => it, | ||
610 | _ => return false, | ||
611 | }; | ||
612 | let (node, repeat, trailing_comma) = match rule.as_slice() { | ||
613 | [Rule::Node(node), Rule::Rep(repeat), Rule::Opt(trailing_comma)] => { | ||
614 | (node, repeat, trailing_comma) | ||
615 | } | ||
616 | _ => return false, | ||
617 | }; | ||
618 | let repeat = match &**repeat { | ||
619 | Rule::Seq(it) => it, | ||
620 | _ => return false, | ||
621 | }; | ||
622 | match repeat.as_slice() { | ||
623 | [comma, Rule::Node(n)] if comma == &**trailing_comma && n == node => (), | ||
624 | _ => return false, | ||
625 | } | ||
626 | let name = grammar[*node].name.clone(); | ||
627 | let label = pluralize(&to_lower_snake_case(&name)); | ||
628 | let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) }; | ||
629 | acc.push(field); | ||
630 | true | ||
631 | } | ||
632 | |||
598 | fn deduplicate_fields(ast: &mut AstSrc) { | 633 | fn deduplicate_fields(ast: &mut AstSrc) { |
599 | for node in &mut ast.nodes { | 634 | for node in &mut ast.nodes { |
600 | let mut i = 0; | 635 | let mut i = 0; |
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index e6e7c7518..449b0242f 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram | |||
@@ -17,7 +17,7 @@ Item = | |||
17 | | TraitDef | 17 | | TraitDef |
18 | | TypeAliasDef | 18 | | TypeAliasDef |
19 | | UnionDef | 19 | | UnionDef |
20 | | UseItem | 20 | | Use |
21 | 21 | ||
22 | Module = | 22 | Module = |
23 | Attr* Visibility? 'mod' Name | 23 | Attr* Visibility? 'mod' Name |
@@ -29,6 +29,19 @@ ItemList = | |||
29 | ExternCrate = | 29 | ExternCrate = |
30 | Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';' | 30 | Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';' |
31 | 31 | ||
32 | Rename = | ||
33 | 'as' (Name | '_') | ||
34 | |||
35 | Use = | ||
36 | Attr* Visibility? 'use' UseTree ';' | ||
37 | |||
38 | UseTree = | ||
39 | (Path? '::')? ('*' | UseTreeList ) | ||
40 | | Path Rename? | ||
41 | |||
42 | UseTreeList = | ||
43 | '{' (UseTree (',' UseTree)* ','?)? '}' | ||
44 | |||
32 | FnDef = | 45 | FnDef = |
33 | Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? | 46 | Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? |
34 | ParamList RetType? | 47 | ParamList RetType? |
@@ -395,18 +408,6 @@ Param = | |||
395 | Attr* Pat (':' ascribed_type:TypeRef) | 408 | Attr* Pat (':' ascribed_type:TypeRef) |
396 | | '...' | 409 | | '...' |
397 | 410 | ||
398 | UseItem = | ||
399 | Attr* Visibility? 'use' UseTree ';' | ||
400 | |||
401 | UseTree = | ||
402 | Path ('::' ('*' | UseTreeList)) Rename? | ||
403 | |||
404 | UseTreeList = | ||
405 | '{' UseTree* '}' | ||
406 | |||
407 | Rename = | ||
408 | 'as' Name | ||
409 | |||
410 | Path = | 411 | Path = |
411 | (qualifier:Path '::')? segment:PathSegment | 412 | (qualifier:Path '::')? segment:PathSegment |
412 | 413 | ||