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

Read token attributes? #100

Closed
abrasat opened this issue Aug 6, 2019 · 4 comments
Closed

Read token attributes? #100

abrasat opened this issue Aug 6, 2019 · 4 comments

Comments

@abrasat
Copy link

abrasat commented Aug 6, 2019

When iterating the tokens generated by the tokenizer, is it possible to check if any TokenAttribute (category, example or description) is set, and, if yes, to get their values ? It would be also interesting to be able to check directly if the token list contains any token from a certain category.

@nblumhardt
Copy link
Member

Hi - yes, the token list is just a list of tokens that can be iterated over/processed using foreach, Linq etc. - can you send more details/pseudocode if this doesn't help? Cheers!

@abrasat
Copy link
Author

abrasat commented Aug 7, 2019

Hi,
Thx for the reply.
For instance these would be some tokens

  [Token(Category = "placeholder", Example = "%1")]
  Placeholder1,
  [Token(Category = "placeholder", Example = "%2")]
  Placeholder2,
  [Token(Category = "placeholder", Example = "%3")]
  Placeholder3,
  [Token(Category = "comment", Example = "//")]
  Comment1,
  [Token(Category = "comment", Example = "///")]
  Comment2,
  [Token(Category = "assignment", Example = ":=")]
  Assign,
  [Token(Example = "(")]
  LeftParen,
  [Token(Example = ")")]
  RightParen,
  [Token(Example = ",")]
  Comma,

And these would be some strings to tokenize and parse

var str1 = "#this is a comment line";
var str2 = "var a := b";
var str3 = "printf("Hello %1")"

For instance, it should be checked if a string to parse contains tokens from the "placeholder" category

@nblumhardt
Copy link
Member

Thanks for the follow-up. No, category information isn't exposed right now - you'd need to look it up manually based on Token<T>.Kind.

@abrasat
Copy link
Author

abrasat commented Aug 14, 2019

Ok, thanks

@abrasat abrasat closed this as completed Aug 14, 2019
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

2 participants