Add parsing of type alias statements i.e. the type keyword - #97
Conversation
d04c741 to
52d1a41
Compare
| // 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.
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. |
youknowone
left a comment
There was a problem hiding this comment.
Looks great, thank you so much.
type keyword
| Tok::Lpar | Tok::Lsqb | Tok::Lbrace => nesting += 1, | ||
| Tok::Rpar | Tok::Rsqb | Tok::Rbrace => nesting -= 1, |
There was a problem hiding this comment.
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.
I believe this is valid: type Foo[T] = ....
There was a problem hiding this comment.
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.
Makes sense. I guess we then still need to support skipping over arbitrary tokens.
There was a problem hiding this comment.
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.
MichaReiser
left a comment
There was a problem hiding this comment.
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
typesoft 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