Example #1
0
        public void AmbiguousMatchesFailWithoutTry()
        {
            var abc = Span.EqualTo("ab").Or(Span.EqualTo("ac"));

            AssertParser.FailsWithMessage(abc, "ac",
                                          "Syntax error (line 1, column 2): unexpected `c`, expected `b`.");
        }
Example #2
0
        public void EmptySpanEqualToCharProducesCorrectExpectationsIgnoreCase()
        {
            var equalToA = Span.EqualToIgnoreCase('a');

            AssertParser.FailsWithMessage(equalToA, "",
                                          "Syntax error: unexpected end of input, expected `a`.");
        }
Example #3
0
        public void AmbiguousPrefixMatchesProducePreciseErrors()
        {
            var abc = Span.EqualTo("ab").Try().Or(Span.EqualTo("ac"));

            AssertParser.FailsWithMessage(abc, "ad",
                                          "Syntax error (line 1, column 2): unexpected `d`, expected `b` or `c`.");
        }
        public void ManyReportsCorrectErrorPositionForNonBacktrackingPartialItemMatch()
        {
            var ab   = Character.EqualTo('a').Then(_ => Character.EqualTo('b'));
            var list = ab.Many();

            AssertParser.FailsWithMessage(list, "ababac", "Syntax error (line 1, column 6): unexpected `c`, expected `b`.");
        }
Example #5
0
 public void WhereFailsWhenPredicateDoesNotMatch()
 {
     AssertParser.FailsWithMessage(
         Character.EqualTo('a').Where(a => a != 'a', "character should be an A"),
         "a",
         "Syntax error (line 1, column 1): character should be an A.");
 }
Example #6
0
        public void ErrorMessageFromMatchedTokenProducesMeaningfulError()
        {
            var number = Token.Matching <SExpressionXToken>(x => x.Number < 100, "number less than `100`");

            var numbers = number.AtEnd();

            AssertParser.FailsWithMessage(numbers, "123", new SExpressionXTokenizer(),
                                          "Syntax error (line 1, column 1): unexpected S-Expression Token `123`, expected number less than `100`.");
        }
        public void OneOfReportsCorrectError()
        {
            var names = new[] { "one", "two" };
            TextParser <TextSpan> p = Parse.OneOf(names.Select(Span.EqualTo).ToArray());

            AssertParser.SucceedsWith(p.Select(t => t.ToStringValue()), "one", "one");
            AssertParser.SucceedsWith(p.Select(t => t.ToStringValue()), "two", "two");
            AssertParser.FailsWithMessage(p.Select(t => t.ToStringValue()), "four", "Syntax error (line 1, column 1): unexpected `f`, expected `one` or `two`.");
        }
Example #8
0
        public void ErrorMessageFromLastPartialItemPropagates()
        {
            var atom   = Token.EqualTo(SExpressionToken.Atom);
            var number = Token.EqualTo(SExpressionToken.Number);

            var alternating = number.Then(n => atom).Many().AtEnd();

            AssertParser.FailsWithMessage(alternating, "123 abc 123 123", new SExpressionTokenizer(),
                                          "Syntax error (line 1, column 13): unexpected number `123`, expected atom.");
        }
Example #9
0
        public void ErrorMessagesFromAppliedCharacterParsersPropagate()
        {
            var number = Token.EqualTo(SExpressionToken.Number)
                         .Apply(t => Character.EqualTo('1').Then(_ => Character.EqualTo('x')));

            var numbers = number.AtEnd();

            AssertParser.FailsWithMessage(numbers, "123", new SExpressionTokenizer(),
                                          "Syntax error (line 1, column 2): invalid number, unexpected `2`, expected `x`.");
        }
Example #10
0
        public void ErrorMessageFromIncompleteItemPropagates()
        {
            var atom   = Token.EqualTo(SExpressionToken.Atom);
            var number = Token.EqualTo(SExpressionToken.Number);

            var alternating = number.Then(n => atom).AtEnd();

            AssertParser.FailsWithMessage(alternating, "123", new SExpressionTokenizer(),
                                          "Syntax error: unexpected end of input, expected atom.");
        }
 public void NotFailsIfLookaheadSucceeds()
 {
     AssertParser.FailsWithMessage(Parse.Not(Span.EqualTo("ab")).Then(_ => Character.EqualTo('a')), "ab",
                                   "Syntax error (line 1, column 1): unexpected successful parsing of `ab`.");
 }
Example #12
0
 public void MissingOperandProducesMeaningfulError(Tokenizer <ArithmeticExpressionToken> tokenizer)
 {
     AssertParser.FailsWithMessage(ArithmeticExpressionParser.Lambda, "1 + * 3", tokenizer,
                                   "Syntax error (line 1, column 5): unexpected operator `*`, expected expression.");
 }
Example #13
0
 public void FailedParsingProducesMessage()
 {
     AssertParser.FailsWithMessage(Character.EqualTo('a').Named("hello"), "b", "Syntax error (line 1, column 1): unexpected `b`, expected hello.");
 }
 public void TokenFailedParsingProducesMessage()
 {
     AssertParser.FailsWithMessage(Token.EqualTo('a').Message("hello"), "b", "Syntax error (line 1, column 1): hello.");
 }
 public void TokenNotFailsIfLookaheadSucceeds()
 {
     AssertParser.FailsWithMessage(Parse.Not(Token.Sequence('a', 'b')).Then(_ => Token.EqualTo('a')), "ab",
                                   "Syntax error (line 1, column 1): unexpected successful parsing of `ab`.");
 }
Example #16
0
 public void DroppedClosingParenthesisProducesMeaningfulError(Tokenizer <ArithmeticExpressionToken> tokenizer)
 {
     AssertParser.FailsWithMessage(ArithmeticExpressionParser.Lambda, "1 + (2 * 3", tokenizer,
                                   "Syntax error: unexpected end of input, expected `)`.");
 }
Example #17
0
 public void MissingOperatorProducesMeaningfulError(Tokenizer <ArithmeticExpressionToken> tokenizer)
 {
     AssertParser.FailsWithMessage(ArithmeticExpressionParser.Lambda, "1 3", tokenizer,
                                   "Syntax error (line 1, column 3): unexpected number `3`.");
 }