-
Notifications
You must be signed in to change notification settings - Fork 215
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
Position of the match #183
Comments
If you're writing a parser, you can get the current position using the |
Use var parser =
from leading in Parse.WhiteSpace.Many()
from span in Parse.Identifier(Parse.Letter, Parse.LetterOrDigit).Span()
from trailing in Parse.WhiteSpace.Many()
select span;
var r = parser.TryParse(" Hello!");
var id = r.Value;
Assert.Equal("Hello", id.Value);
Assert.Equal(5, id.Length);
// span.Start is the starting position
Assert.Equal(2, id.Start.Pos);
Assert.Equal(1, id.Start.Line);
Assert.Equal(3, id.Start.Column);
// span.End is the ending position
Assert.Equal(7, id.End.Pos);
Assert.Equal(1, id.End.Line);
Assert.Equal(8, id.End.Column); |
public interface ITextSpan<T>
{
T Value { get; }
Position Start { get; }
Position End { get; }
int Length { get; }
} |
Is there an example of how to use it? |
Just append var parser =
from leading in Parse.WhiteSpace.Many()
from span in Parse.Identifier(Parse.Letter, Parse.LetterOrDigit).Span() // <- here
from trailing in Parse.WhiteSpace.Many()
select span; The parser above will return |
Can I find out the position where the match was found?
The text was updated successfully, but these errors were encountered: