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

How to use Token.Sequence() #44

Closed
powerdude opened this issue Jul 1, 2018 · 3 comments
Closed

How to use Token.Sequence() #44

powerdude opened this issue Jul 1, 2018 · 3 comments

Comments

@powerdude
Copy link
Contributor

Hello,

I'm not sure how to use Token.Sequence() like Token.EqualTo(). Can you provide an example? I'm trying to do this:

public static TokenListParser<MyToken, int> MySpecialNumber = Token.Sequence(MyToken.Number, MyToken.Word).Apply(Numerics.IntegerInt32); 

but it fails because the text parser can't take a series of tokens. What is a valid use case for this method or what kind of parser do i have to create to use Apply?

@nblumhardt
Copy link
Member

Hi @powerdude -

In this case you probably want something like:

public static TokenListParser<MyToken, int> MySpecialNumber = 
  Token.EqualTo(MyToken.Number).Apply(Numerics.IntegerInt32))
    .Then(n => Token.EqualTo(MyToken.Word).Value(n));

HTH!
Nick

@dhowe
Copy link

dhowe commented Oct 9, 2018

Still be good to have an example of how this function works...

@nblumhardt
Copy link
Member

It's a helper for cases like: Token.Sequence(Token.Yield, Token.Break) 👍

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

3 participants