From 70f50be3731f94b61c594dc6e23b0dec5e6a0fdf Mon Sep 17 00:00:00 2001 From: ddwightx Date: Sun, 27 Mar 2022 20:29:33 -0400 Subject: [PATCH] Fixed toString for LazyPatternMatcher (cherry picked from commit 1ad81acf24e624242ae156368d60acb0433506b7) --- docs/Examples.md | 466 +++++++++--------- .../Input/Patterns/LazyPatternMatcher.cs | 27 +- src/Matcher/Matcher.csproj | 2 +- .../Files/JsonLanguageDefinition.json | 111 +++++ .../TestJsonParser/Tests/JsonParserTests.cs | 64 +-- 5 files changed, 400 insertions(+), 270 deletions(-) create mode 100644 src/Tests/StaxeTests/TestJsonParser/Files/JsonLanguageDefinition.json diff --git a/docs/Examples.md b/docs/Examples.md index da21120..7cf718c 100644 --- a/docs/Examples.md +++ b/docs/Examples.md @@ -3,16 +3,18 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests/StaxeTests) provide various examples of using the Staxe.Matcher, Staxe.Generator, and Staxe.Executor libraries to build languages with a variety of features. ## JSON Parser -[Grammar](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/Shared/Matcher/LanguageMatcherProvider.cs#L59) + +[Code-Based Grammar](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/Shared/Matcher/LanguageMatcherProvider.cs#L59), [JSON-Based Grammar](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/TestJsonParser/Files/JsonLanguageDefinition.json) ### Features + - Provides similar feature to System.Json.JsonValue derived classes - Library Usages: Staxe.Matcher - -### Sample +### Sample #### Language Code + ```json { "firstName": "John", @@ -23,7 +25,7 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests "city": "New York", "state": "NY", "postalCode": "10021", - "owner": true + "owner": true }, "phoneNumber": [ { @@ -42,6 +44,7 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests ``` #### Matcher Output (AST) + ```xml @@ -120,12 +123,13 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests ``` - ## Expression Language + [Grammar](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/TestExpressionLang/Files/StaxeTestExpressionLangDefinition.json)
[Instruction Generator](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/TestExpressionLang/Engine/Generator/InstructionGenerator.cs) ### Features + - Custom Instructions - Restrict operators between Booleans and Numbers - Library Usages: Staxe.Matcher, Staxe.Generator, Staxe.Executor @@ -133,11 +137,13 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests ### Sample #### Language Code + ``` 1 + 3 + 5 + 7! * 2 * 4 * 6 + 9 + 11^2 + 13 * 8 * 10 * 12 ``` #### Matcher Output (AST) + ```xml @@ -193,47 +199,50 @@ The tests in [StaxeTests](https://github.com/synfron/Staxe/tree/master/src/Tests ``` #### Optimized Instructions + ``` CPR 0, 2, vr, 1, vr, 3 -RPlus -PHR +RPlus +PHR VR 5 -RPlus -PHR +RPlus +PHR VR 7 SPL "RFAC" -PHR +PHR VR 2 -RMultiply -PHR +RMultiply +PHR VR 4 -RMultiply -PHR +RMultiply +PHR VR 6 -RMultiply -RPlus -PHR +RMultiply +RPlus +PHR VR 9 -RPlus +RPlus CPR 0, 2, vr, 11, vr, 2 SPL "RPOW" -RPlus +RPlus CPR 0, 2, vr, 13, vr, 8 -RMultiply -PHR +RMultiply +PHR VR 10 -RMultiply -PHR +RMultiply +PHR VR 12 -RMultiply +RMultiply RPlus ``` ## Simple Language + [Grammar](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/TestSimpleLang/Files/StaxeTestSimpleLangDefinition.json)
[Instruction Generator](https://github.com/synfron/Staxe/blob/master/src/Tests/StaxeTests/TestSimpleLang/Engine/Generator/InstructionGenerator.cs) ### Features + - Closures - First-class functions - Simplified number handling @@ -242,6 +251,7 @@ RPlus ### Sample #### Language Code + ```csharp var fibonacci = $(n) { var a = 0; @@ -270,6 +280,7 @@ getFib(44); ``` #### Matcher Output (AST) + ```xml