You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
check the value of a state variable ( foo : bool )
get the position of the current line and column (the current position)
if the code assertion fails stop trying this rule (when foo is false this rule should not succeed).
Is this possible in Sprache?
public static readonly Parser<string> QuotedText =
(from open in Parse.Char('"') if(foo()){ Console.WriteLine(_the current position_)} else {stop to parse this rule};
from content in Parse.CharExcept('"').Many().Text()
from close in Parse.Char('"')
select content).Token();
static readonly Parser<string> Identifier =
from first in Parse.Letter.Once()
from rest in Parse.LetterOrDigit.XOr(Parse.Char('-')).XOr(if(foo()){ Console.WriteLine(_the current position_)} else {stop to parse this rule}; Parse.Char('_')).Many()
select new string(first.Concat(rest).ToArray());
The text was updated successfully, but these errors were encountered:
How to add line and column to an ParseException? As I see Sprache does not add them to the exception.Data object? Is there a global state?
static readonly Parser<string> _char =
from first in Parse.Letter select first.ToString();
static readonly Parser<string> nl =
from first in Parse.String("\n")
.XOr(Parse.String("\r\n"))
.XOr(Parse.String("\r"))
select "";
public static Parser<string> verb =
from aa in Parse.String("verb")
from a2 in Parse.String("*").Optional()
from a3 in _char.Not()
from a4 in Parse.AnyChar
from a5 in Parse.AnyChar.Except(Parse.Char(a4)).Except(nl).Many().Text()
from a6 in Parse.AnyChar
where a4 == a6 ? true : throw new ParseException("MESSAGE") (HOW TO ADD LINE, COLUMN)
select a2.IsEmpty ? "isVerb" : "isVerb*";
Sprache is stateless, so there is no global state.
To get the position, use Span(), something like this (not tested):
publicstaticParser<string>verb=// ... the first 5 lines are the same ...froma6inParse.AnyChar.Span()wherea4==a6.Value?true:thrownewException($"Error at: {a6.Start.Line}, {a6.Start.Column}")selecta2.IsEmpty?"isVerb":"isVerb*";
E.g we have the parsers below. I want to
Is this possible in Sprache?
The text was updated successfully, but these errors were encountered: