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 recognize strings? #109

Closed
johnny0914 opened this issue Apr 26, 2018 · 3 comments
Closed

How to recognize strings? #109

johnny0914 opened this issue Apr 26, 2018 · 3 comments

Comments

@johnny0914
Copy link

Hi, I am trying to create a basic Latex parser. I saw some implementations in javascript using PEG.js. Now I am using Pegasus to create the parser in C#.
Unfortunatly I have some issues. I do not fully understand the outputs from the rules.

For example I want to recognize strings containing lower case letters.

str= c:[a-z]+ { c }

And I get the following error:
Cannot implicitly convert type 'System.Collections.Generic.IList' to 'string'

What exactly is the output of repeated occurrence of expression (in this case c)? Is it a string? an array of chars? Is "str= c:[a-z]+ { c }" even valid?

@johnny0914
Copy link
Author

I tried the following:
decimal = value:([a-zA-Z]+"") { value }
and got errors.
Next I have replaced "decimal" by "_decimal":
_decimal = value:([a-zA-Z]+"") { value }
and could recognize strings.

Are some names reserved?
And how to get rid of the quotation mark in
_decimal = value:([a-zA-Z]+"") { value }
?

@otac0n
Copy link
Owner

otac0n commented Apr 27, 2018

You can use string.Concat if you want to avoid the quotes.

number = chars:[a-z]i+ { string.Concat(chars) }

This also makes use of case insensitive strings.

Note that it is allowed to use C# keywords as variables, but not as rule names:

other = decimal:[a-z]i+ { string.Concat(@decimal) }

@otac0n
Copy link
Owner

otac0n commented May 4, 2018

Discussion related to supporting keywords as names continues in #107

@otac0n otac0n closed this as completed May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants