Skip to content
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 support for leading | and & in types #306

Merged
merged 14 commits into from
Jul 27, 2024
Merged

Conversation

jackdotink
Copy link
Contributor

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.

) -> ParserResult<ast::TypeInfo> {
let mut is_union = false;
let mut is_intersection = false;

let mut types = Punctuated::new();

let leading = if simple_type.is_some() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or_else probably better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I would use or_else on here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see--it is inverted

let mut current_type = simple_type;

loop {
let Ok(current_token) = state.current() else {
return ParserResult::NotFound;
let ty = if current_type.is_some() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.take().unwrap_or_else(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work because of the return

CHANGELOG.md Show resolved Hide resolved
full-moon/src/ast/parsers.rs Outdated Show resolved Hide resolved
full-moon/src/ast/parsers.rs Outdated Show resolved Hide resolved
full-moon/src/ast/parsers.rs Outdated Show resolved Hide resolved
@Kampfkarren Kampfkarren merged commit 4bb43f2 into Kampfkarren:main Jul 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants