public void Parse_WithNoRules_YieldsEmptyGrammar() { var subject = string.Empty; var parser = new PegParser(); var grammar = parser.Parse(subject); Assert.That(grammar.Rules, Is.Empty); }
public void Parse_WithLiteralExpression_YieldsLiteralExpressionWithCorrectCaseSensitivity(string subject, bool ignoreCase) { var parser = new PegParser(); var grammar = parser.Parse(subject); var literal = (LiteralExpression)grammar.Rules.Single().Expression; Assert.That(literal.IgnoreCase, Is.EqualTo(ignoreCase)); }
public void Parse_WithClassExpression_YieldsClassExpressionWithCorrectCaseSensitivity(string subject, bool?ignoreCase) { var parser = new PegParser(); var grammar = parser.Parse(subject); var charClass = (ClassExpression)grammar.Rules.Single().Expression; Assert.That(charClass.IgnoreCase, Is.EqualTo(ignoreCase)); }
public void Parse_WhenTheGrammarIsEntirelyEmpty_ReturnsAnEmptySequence(string subject) { var parser = new PegParser(); var grammar = parser.Parse(subject); var result = (SequenceExpression)grammar.Rules.Single().Expression; Assert.That(result.Sequence, Is.Empty); }
public void Parse_WithClassExpression_YieldsClassExpressionWithCorrectCaseSensitivity(string subject, bool? ignoreCase) { var parser = new PegParser(); var grammar = parser.Parse(subject); var charClass = (ClassExpression)grammar.Rules.Single().Expression; Assert.That(charClass.IgnoreCase, Is.EqualTo(ignoreCase)); }
public void Parse_WithSingleEmptyRule_YieldsRuleWithMatchingName() { var subject = "testName = "; var parser = new PegParser(); var grammar = parser.Parse(subject); Assert.That(grammar.Rules.Single().Identifier.Name, Is.EqualTo("testName")); }
public void RepeatResets() { var grammar = TestGrammar.Create(); var parser = new PegParser <TestData>(grammar, grammar.Root()); var input = "AAABBBBB"; var result = parser.Parse(input); Assert.AreEqual(input, result.Items); }
public void Parse_WithPegGrammar_Works() { var subject = File.ReadAllText("PegParser.peg"); var parser = new PegParser(); var result = parser.Parse(subject); Assert.That(result, Is.Not.Null); }
public void Parse_WithNoRules_YieldsEmptyGrammar() { var subject = string.Empty; var parser = new PegParser(); var grammar = parser.Parse(subject); Assert.That(grammar.Rules, Is.Empty); }
public void CaptureInitializedProperly() { var grammar = TestGrammar.Create(); var parser = new PegParser <TestData>(grammar, grammar.Root()); var input = "AAABBBBB"; var result = parser.Parse(input); Assert.AreEqual(input, result.Items); }
public void Parse_WhenTheGrammarIsEntirelyEmpty_ReturnsAnEmptySequence(string subject) { var parser = new PegParser(); var grammar = parser.Parse(subject); var result = (SequenceExpression)grammar.Rules.Single().Expression; Assert.That(result.Sequence, Is.Empty); }
public void Parse_WithSingleEmptyRule_YieldsRuleWithEmptySequenceExpression() { var subject = "a = "; var parser = new PegParser(); var grammar = parser.Parse(subject); var sequence = (SequenceExpression)grammar.Rules.Single().Expression; Assert.That(sequence.Sequence, Is.Empty); }
public void Parse_WithLiteralExpression_YieldsLiteralExpressionWithCorrectString() { var subject = "a = 'testString'"; var parser = new PegParser(); var grammar = parser.Parse(subject); var literal = (LiteralExpression)grammar.Rules.Single().Expression; Assert.That(literal.Value, Is.EqualTo("testString")); }
public void Parse_WithCodeExpression_YieldsCodeExpressionWithCorrectCodeType(string subject, CodeType codeType, bool inSequence) { var parser = new PegParser(); var grammar = parser.Parse(subject); var expression = grammar.Rules.Single().Expression; var codeExpression = (CodeExpression)(inSequence ? ((SequenceExpression)expression).Sequence.Single() : expression); Assert.That(codeExpression.CodeType, Is.EqualTo(codeType)); }
public void Parse_WithLiteralExpression_YieldsLiteralExpressionWithCorrectString() { var subject = "a = 'testString'"; var parser = new PegParser(); var grammar = parser.Parse(subject); var literal = (LiteralExpression)grammar.Rules.Single().Expression; Assert.That(literal.Value, Is.EqualTo("testString")); }
public void Compile_WithExpressionWhoseTypeIsNotDefined_YieldsError() { var parser = new PegParser(); var grammar = parser.Parse("a -memoize = a;"); var result = PegCompiler.Compile(grammar); var error = result.Errors.Single(); Assert.That(error.ErrorNumber, Is.EqualTo("PEG0019")); Assert.That(error.IsWarning, Is.False); }
public void Compile_WithUnmemoizedLeftRecursion_YieldsError(string subject) { var parser = new PegParser(); var grammar = parser.Parse(subject); var result = PegCompiler.Compile(grammar); var error = result.Errors.First(); Assert.That(error.ErrorNumber, Is.EqualTo("PEG0020")); Assert.That(error.IsWarning, Is.False); }
public void Parse_WhenACSharpExpressionDoesntConsumeAllOfTheSourceText_YieldsError() { var parser = new PegParser(); try { parser.Parse("a = {{ return \"OK\"; } extra }"); } catch (FormatException ex) { Assert.That(ex.Message, Is.StringStarting("PEG0011:")); var cursor = (Cursor)ex.Data["cursor"]; Assert.That(cursor.Location, Is.EqualTo(22)); } }
public void Compile_WithComplexLeftRecursion_Succeeds() { var parser = new PegParser(); var grammar = parser.Parse(@"a<o> -memoize = b; b<o> -memoize = c; c<o> -memoize = e / d; d<o> = e; e<o> -memoize = f; f<o> -memoize = g; g<o> -memoize = g;"); var result = PegCompiler.Compile(grammar); Assert.That(result.Errors, Is.Empty); }
public void Parse_WhenACSharpExpressionDoesntConsumeAllOfTheSourceText_YieldsError() { var parser = new PegParser(); try { parser.Parse("a = {{ return \"OK\"; } extra }"); } catch (FormatException ex) { Assert.That(ex.Message, Is.StringStarting("PEG0011:")); var cursor = (Cursor)ex.Data["cursor"]; Assert.That(cursor.Location, Is.EqualTo(22)); } }
public void Parse_WithClassExpression_YieldsClassExpressionWithCorrectCharacterRanges() { var subject = "a = [-a-z0-9]"; var parser = new PegParser(); var grammar = parser.Parse(subject); var charClass = (ClassExpression)grammar.Rules.Single().Expression; var expected = new[] { new CharacterRange('-', '-'), new CharacterRange('a', 'z'), new CharacterRange('0', '9'), }; Assert.That(charClass.Ranges, Is.EquivalentTo(expected)); }
public void Parse_WithClassExpression_YieldsClassExpressionWithCorrectCharacterRanges() { var subject = "a = [-a-z0-9]"; var parser = new PegParser(); var grammar = parser.Parse(subject); var charClass = (ClassExpression)grammar.Rules.Single().Expression; var expected = new[] { new CharacterRange('-', '-'), new CharacterRange('a', 'z'), new CharacterRange('0', '9'), }; Assert.That(charClass.Ranges, Is.EquivalentTo(expected)); }
public void Parse_WithPegGrammar_Works() { var subject = File.ReadAllText("PegParser.peg"); var parser = new PegParser(); var result = parser.Parse(subject); Assert.That(result, Is.Not.Null); }
public void Compile_WithComplexLeftRecursion_Succeeds() { var parser = new PegParser(); var grammar = parser.Parse(@"a<o> -memoize = b; b<o> -memoize = c; c<o> -memoize = e / d; d<o> = e; e<o> -memoize = f; f<o> -memoize = g; g<o> -memoize = g;"); var result = PegCompiler.Compile(grammar); Assert.That(result.Errors, Is.Empty); }
public void Parse_WithSingleEmptyRule_YieldsRuleWithMatchingName() { var subject = "testName = "; var parser = new PegParser(); var grammar = parser.Parse(subject); Assert.That(grammar.Rules.Single().Identifier.Name, Is.EqualTo("testName")); }
public void Parse_WithSingleEmptyRule_YieldsRuleWithEmptySequenceExpression() { var subject = "a = "; var parser = new PegParser(); var grammar = parser.Parse(subject); var sequence = (SequenceExpression)grammar.Rules.Single().Expression; Assert.That(sequence.Sequence, Is.Empty); }
public void Parse_WhenACSharpExpressionHasUnbalancedCurlyBraces_Succeeds() { var parser = new PegParser(); Assert.That(() => parser.Parse("curly = { \"{\" }"), Throws.Nothing); }
public static InputString Parse(string s) { return(Parser.Parse(s)); }
public static JsonPathExpression Parse(string s) { return(Parser.Parse(s)); }
public void Parse_WhenACSharpExpressionHasUnbalancedCurlyBraces_Succeeds() { var parser = new PegParser(); Assert.That(() => parser.Parse("curly = { \"{\" }"), Throws.Nothing); }
public void Compile_WithExpressionWhoseTypeIsNotDefined_YieldsError() { var parser = new PegParser(); var grammar = parser.Parse("a -memoize = a;"); var result = PegCompiler.Compile(grammar); var error = result.Errors.Single(); Assert.That(error.ErrorNumber, Is.EqualTo("PEG0019")); Assert.That(error.IsWarning, Is.False); }
public void Compile_WithUnmemoizedLeftRecursion_YieldsError(string subject) { var parser = new PegParser(); var grammar = parser.Parse(subject); var result = PegCompiler.Compile(grammar); var error = result.Errors.First(); Assert.That(error.ErrorNumber, Is.EqualTo("PEG0020")); Assert.That(error.IsWarning, Is.False); }
public void Parse_WithCodeExpression_YieldsCodeExpressionWithCorrectCodeType(string subject, CodeType codeType, bool inSequence) { var parser = new PegParser(); var grammar = parser.Parse(subject); var expression = grammar.Rules.Single().Expression; var codeExpression = (CodeExpression)(inSequence ? ((SequenceExpression)expression).Sequence.Single() : expression); Assert.That(codeExpression.CodeType, Is.EqualTo(codeType)); }