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

parse use statements #1

Open
Lokathor opened this issue Aug 13, 2022 · 0 comments
Open

parse use statements #1

Lokathor opened this issue Aug 13, 2022 · 0 comments

Comments

@Lokathor
Copy link
Owner

Zesterer said that this should work:

enum Head {
    Single(Ident),
    Many(Vec<Import>),
}

struct Import {
    path: Vec<Ident>,
    head: Box<Head>,
}

let import = recursive(|import| {
    let head = ident.map(Head::Single)
        .or(import
            .separated_by(comma)
            .delimited_by(lbrace, rbrace)
            .map(Head::Many));
    let path = ident.then_ignore(separator).repeated();

    path.then(head).map(|(path, head)| Import { path, head })
});

let import_statement = just(use)
    .ignore_then(import)
    .then_ignore(semicolon);
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

No branches or pull requests

1 participant