Skip to content

How would go about building parsers at runtime? #221

Answered by zesterer
schneiderfelipe asked this question in Q&A
Discussion options

You must be logged in to vote

Normally, parsers (like iterators) have a unique type that depends on how you compose them.

For example, the type of just("a").or(just("b")) will look something like Or<Just<...>, Just<...>>.

If you're trying to build up parsers at runtime, this is obviously not particularly useful. 'Simple' code like the following will fail to compile due to the parsers having mismatched types:

let twitter_alias = just('@').ignore_then(text::ident());

let mastodon_alias = just('@')
    .ignore_then(text::ident())
    .chain(just('@').ignore_then(url));

// Error: type mismatch between match arms
let alias_parser = match get_alias_mode_at_runtime() {
    AliasMode::Twitter => twitter_alias,
    AliasMode::

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@schneiderfelipe
Comment options

@Troels51
Comment options

@zesterer
Comment options

@Troels51
Comment options

@Troels51
Comment options

Answer selected by schneiderfelipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants