-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parsing of type alias statements i.e. the type
keyword
#97
Conversation
d04c741
to
52d1a41
Compare
parser/src/soft_keywords.rs
Outdated
// 2. The type token is followed by a name token. | ||
// 3. The name token is followed by an equality token. | ||
else if matches!(tok, Tok::Type) { | ||
if !self.start_of_line { |
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.
I'll look at this on Monday. I need a fresh mind to process this
Nice job figuring this out. A couple questions to confirm my understanding of the soft-keyword heuristics. |
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.
Looks great, thank you so much.
type
keyword
parser/src/soft_keywords.rs
Outdated
Tok::Lpar | Tok::Lsqb | Tok::Lbrace => nesting += 1, | ||
Tok::Rpar | Tok::Rsqb | Tok::Rbrace => nesting -= 1, |
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.
Do we need to support parentheses for the type
case? I didn't see any test case that uses a parenthesized name.
I think we can be more strict in the type
implementation and only skip over NonLogicalNewline
, Continuation
, and Comment
. Whatever token comes after must be the =
or it isn't a type assignment
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.
I believe this is valid: type Foo[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.
Yeah I cannot find a case where parens are allowed, although we do need to support brackets for the generic definition
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.
Makes sense. I guess we then still need to support skipping over arbitrary tokens.
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.
These are generally syntax errors and won't result in an identifier at runtime so I'm actually not sure if we want to change the type token to an identifier.
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.
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.
Ready to merge when you are
…hon#97) Extends RustPython#95 Closes RustPython#82 Adds parsing of new `type` soft keyword for defining type aliases. Supports type alias statements as defined in PEP 695 e.g. ```python type IntOrStr = int | str type ListOrSet[T] = list[T] | set[T] type AnimalOrVegetable = Animal | "Vegetable" type RecursiveList[T] = T | list[RecursiveList[T]] ``` All type parameter kinds are supported as in RustPython#95. Builds on soft keyword abstractions introduced in RustPython/RustPython#4519
…hon#97) Extends RustPython#95 Closes RustPython#82 Adds parsing of new `type` soft keyword for defining type aliases. Supports type alias statements as defined in PEP 695 e.g. ```python type IntOrStr = int | str type ListOrSet[T] = list[T] | set[T] type AnimalOrVegetable = Animal | "Vegetable" type RecursiveList[T] = T | list[RecursiveList[T]] ``` All type parameter kinds are supported as in RustPython#95. Builds on soft keyword abstractions introduced in RustPython/RustPython#4519
Extends #95
Closes #82
Adds parsing of new
type
soft keyword for defining type aliases.Supports type alias statements as defined in PEP 695 e.g.
All type parameter kinds are supported as in #95.
Builds on soft keyword abstractions introduced in RustPython/RustPython#4519