-
Notifications
You must be signed in to change notification settings - Fork 19
Update for new stable and unstable features, and fix a few mistakes. #68
base: master
Are you sure you want to change the base?
Changes from all commits
dd1f35c
db0a296
7936b13
72d5a0a
82efb69
c815b25
3d773d9
159762b
d3d3d02
d3aa7da
62017c0
2c34092
eeeae03
4ede4ea
152276a
5560302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
/.vscode |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,19 @@ ItemKind = | |
auto:"auto"? | ||
"trait" name:IDENT generics:Generics? | ||
{ ":" superbounds:TypeBound* %% "+" }? | ||
where_clause:WhereClause? "{" trait_items:TraitItem* "}" | ||
where_clause:WhereClause? "{" attrs:InnerAttr* trait_items:TraitItem* "}" | ||
} | ||
// unstable(trait_alias): | ||
| TraitAlias:{ | ||
"trait" name:IDENT generics:Generics? | ||
{ ":" superbounds:TypeBound* %% "+" }? | ||
where_clause:WhereClause? "=" bounds:TypeBound* %% "+" ";" | ||
"trait" name:IDENT generics:Generics? "=" bounds:TypeBound* %% "+" | ||
where_clause:WhereClause? ";" | ||
} | ||
| Impl:{ | ||
// unstable(specialization): | ||
defaultness:"default"? | ||
unsafety:"unsafe"? "impl" generics:Generics? | ||
// unstable(const_trait_impl) | ||
constness:"const"? | ||
{ negate:"!"? trait_path:Path "for" }? ty:Type | ||
where_clause:WhereClause? "{" attrs:InnerAttr* impl_items:ImplItem* "}" | ||
} | ||
|
@@ -84,20 +85,23 @@ ImplItemKind = | |
| MacroCall:ItemMacroCall | ||
; | ||
|
||
FnHeader = constness:"const"? unsafety:"unsafe"? asyncness:"async"? { "extern" abi:Abi }?; | ||
FnDecl = name:IDENT generics:Generics? "(" args:FnArgs? ")" { "->" ret_ty:Type }? where_clause:WhereClause?; | ||
FnHeader = constness:"const"? asyncness:"async"? unsafety:"unsafe"? { "extern" abi:Abi }?; | ||
FnDecl = name:IDENT generics:Generics? "(" params:FnParams? ")" { "->" ret_ty:Type }? where_clause:WhereClause?; | ||
|
||
// FIXME(eddyb) find a way to express this `A* B?` pattern better | ||
FnArgs = | ||
| Regular:FnArg+ %% "," | ||
| Variadic:"..." | ||
| RegularAndVariadic:{ args:FnArg+ % "," "," "..." } | ||
FnParams = | ||
| Regular:FnParam+ %% "," | ||
| CVariadic:FnCVariadicParam | ||
| RegularAndCVariadic:{ args:FnParam+ % "," "," c_variadic:FnCVariadicParam } | ||
Comment on lines
+94
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
; | ||
FnArg = | ||
FnParam = attrs:OuterAttr* kind:FnParamKind; | ||
FnParamKind = | ||
| SelfValue:{ mutable:"mut"? "self" } | ||
| SelfRef:{ "&" lt:LIFETIME? mutable:"mut"? "self" } | ||
Comment on lines
99
to
100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| Regular:FnSigInput | ||
| Regular:{ { pat:Pat ":" }? ty:Type } | ||
; | ||
// unstable(c_variadic): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax itself is stable so you can remove this. |
||
FnCVariadicParam = attrs:OuterAttr* { pat:Pat ":" }? "..."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more like this: FnParamKind =
| SelfParam: FnSelfParam
| Regular:{ { pat:Pat ":" }? ty:FnParamType }
;
FnParamType =
| CVariadic: "..."
| Regular: Type
; |
||
|
||
EnumVariant = attrs:OuterAttr* name:IDENT kind:EnumVariantKind { "=" discr:Expr }?; | ||
EnumVariantKind = | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,18 +1,30 @@ | ||||||
Pat = | ||||||
| Wild:"_" | ||||||
| Rest:".." | ||||||
| Literal:{ minus:"-"? lit:LITERAL } | ||||||
// unstable(exclusive_range_pattern): | ||||||
| Range:{ start:PatRangeValue ".." end:PatRangeValue } | ||||||
| RangeInclusive:{ start:PatRangeValue { "..." | "..=" } end:PatRangeValue } | ||||||
| Range:{ | ||||||
| start:PatRangeValue ".." end:PatRangeValue | ||||||
// unstable(half_open_range_patterns): | ||||||
| start:PatRangeValue ".." | ".." end:PatRangeValue | ||||||
} | ||||||
| RangeInclusive:{ | ||||||
| start:PatRangeValue { "..." | "..=" } end:PatRangeValue | ||||||
Centril marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// unstable(half_open_range_patterns): | ||||||
| { "..." | "..=" } end:PatRangeValue | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
| Binding:{ binding:Binding { "@" subpat:Pat }? } | ||||||
| Paren:{ "(" pat:Pat ")" } | ||||||
| Ref:{ "&" mutable:"mut"? pat:Pat } | ||||||
// unstable(box_patterns): | ||||||
| Box:{ "box" pat:Pat } | ||||||
| Slice:{ "[" elems:SlicePatElem* %% "," "]" } | ||||||
| Tuple:{ "(" fields:TuplePatField* %% "," ")" } | ||||||
// unstable(or_patterns): | ||||||
// FIXME(eddyb) find a way to express "2 or more" (like regex `{2,}`). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively you can just explain this as a binary operator rather than a list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair, it's just weird to think of it as a binary operator because it's fully commutative and associative. |
||||||
| Or:{ first_pat:Pat "|" pats:Pat+ % "|" } | ||||||
| Slice:{ "[" elems:Pat* %% "," "]" } | ||||||
| Tuple:{ "(" fields:Pat* %% "," ")" } | ||||||
| Path:QPath | ||||||
| TupleStruct:{ path:Path "(" fields:TuplePatField* %% "," ")" } | ||||||
| TupleStruct:{ path:Path "(" fields:Pat* %% "," ")" } | ||||||
| Struct:{ path:Path "{" fields:StructPatFieldsAndEllipsis "}" } | ||||||
| MacroCall:MacroCall | ||||||
; | ||||||
|
@@ -24,24 +36,15 @@ PatRangeValue = | |||||
|
||||||
Binding = boxed:"box"? reference:"ref"? mutable:"mut"? name:IDENT; | ||||||
|
||||||
SlicePatElem = | ||||||
| Subslice:{ subpat:Pat? ".." } | ||||||
| Pat:Pat | ||||||
; | ||||||
|
||||||
TuplePatField = | ||||||
| Ellipsis:".." | ||||||
| Pat:Pat | ||||||
; | ||||||
|
||||||
// FIXME(eddyb) find a way to express this `A* B?` pattern better | ||||||
StructPatFieldsAndEllipsis = | ||||||
| Fields:StructPatField* %% "," | ||||||
| Ellipsis:{ ".." } | ||||||
| FieldsAndEllipsis:{ fields:StructPatField+ % "," "," ".." } | ||||||
; | ||||||
|
||||||
StructPatField = | ||||||
StructPatField = attrs:OuterAttr* kind:StructPatFieldKind; | ||||||
StructPatFieldKind = | ||||||
| Shorthand:Binding | ||||||
| Explicit:{ field:FieldName ":" pat:Pat } | ||||||
; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ Type = | |
|
||
FnSigInputs = | ||
| Regular:FnSigInput+ %% "," | ||
| Variadic:"..." | ||
| RegularAndVariadic:{ inputs:FnSigInput+ % "," "," "..." } | ||
| CVariadic:FnSigCVariadicInput | ||
| RegularAndCVariadic:{ inputs:FnSigInput+ % "," "," c_variadic:FnSigCVariadicInput } | ||
; | ||
FnSigInput = { pat:Pat ":" }? ty:Type; | ||
FnSigInput = attrs:OuterAttr* { pat:Pat ":" }? ty:Type; | ||
FnSigCVariadicInput = attrs:OuterAttr* "..."; | ||
Comment on lines
22
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't right; the actual grammar is defined by: fn parse_ty_bare_fn(&mut self, generic_params: Vec<GenericParam>) -> PResult<'a, TyKind> {
let unsafety = self.parse_unsafety();
let ext = self.parse_extern()?;
self.expect_keyword(kw::Fn)?;
let decl = self.parse_fn_decl(|_| false, AllowPlus::No)?;
Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params, decl })))
} Aside from that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'd rather move the full grammar here than have a separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I've made some changes recently in the large scale parser refactorings to simplify things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to review the new tests and PR descriptions in:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this setup, where nested or-patterns are unstable, then
match 0 { 0 | 1 => 0 }
is also unstable but it isn't.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a proper stability setup, but I can undo this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just leave a comment instead. You might want to double check
if/while let
also.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we annoyingly don't allow
fn foo(Ok(x) | Err(x): _);
but require parens around the pattern instead.