Kampfkarren / full-moon

A lossless Lua 5.1 parser
Mozilla Public License 2.0
379 stars 49 forks source link

Add support for leading `|` and `&` in types #306

Closed jackdotink closed 2 months ago

jackdotink commented 3 months ago

This PR changes TypeInfo::Union and TypeInfo::Intersection to both use a separate struct: TypeUnion and TypeIntersection. It also changes the structure of these types from being linked lists into Vecs (using Punctuated). This also results in some new visitor methods: visit_type_union, visit_type_union_end, visit_type_intersection, and visit_type_intersection_end.

This PR also adds the ability to parse leading | and & in types, such as:

type T = | "A" | "B" | "C"

This involved adding a leading field to the TypeUnion and TypeIntersection structs, which contains an optional TokenReference.

Tests were updated to accommodate the changes, and leading | and & was added to the types test.