Skip to content

Commit 92186a2

Browse files
committed
Read the calculator's EGT file from the sample project's Base-64 grammar.
The hell of tinkering it needed!
1 parent 60dd353 commit 92186a2

File tree

11 files changed

+18
-55
lines changed

11 files changed

+18
-55
lines changed

Diff for: sample/Farkle.Calculator/Program.fs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
open Farkle
77
open System
88
open Farkle.PostProcessor
9+
open SimpleMaths
910

1011
let inline prettyPrintResult x =
1112
match x with

Diff for: sample/Farkle.Samples.FSharp/Farkle.Samples.FSharp.fsproj

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
6-
<!-- I added the calculator here as well, to demonstrate that it works with many Farkle items.
7-
It doesn't have anything to do with JSON, but renaming the project is too much of an effort. -->
8-
<Farkle Include="..\SimpleMaths.egt" Namespace="SimpleMaths" />
6+
<Farkle Include="SimpleMaths.egt" Namespace="SimpleMaths" />
97
<Compile Include="SimpleMaths.g.fs" />
108
<Compile Include="JSON.fs" />
119
<Compile Include="GOLDMetaLanguage.fs" />
File renamed without changes.

Diff for: sample/Farkle.Samples.FSharp/SimpleMaths.fs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
55

6-
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
7-
module SimpleMaths
6+
// Having a midule named SimpleMaths effectively
7+
// hides the SimpleMaths.Definitions namespace.
8+
module SimpleMaths.SimpleMaths
89

910
open Farkle
1011
open Farkle.Builder
File renamed without changes.

Diff for: sample/JSON.egt

-4.57 KB
Binary file not shown.

Diff for: sample/JSON.grm

-42
This file was deleted.

Diff for: tests/Farkle.Tests/Generators.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open Farkle.Collections
1515
open Farkle.Grammar
1616
open Farkle.IO
1717
open FsCheck
18-
open SimpleMaths
18+
open SimpleMaths.SimpleMaths
1919
open System.Collections.Generic
2020
open System.IO
2121
open System.Text

Diff for: tests/Farkle.Tests/GrammarEquivalenceTests.fs

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open Farkle.Builder
1111
open Farkle.Grammar
1212
open Farkle.PostProcessor
1313
open Farkle.Tests
14+
open SimpleMaths
1415
open System.Collections.Generic
1516
open System.Collections.Immutable
1617

@@ -110,16 +111,20 @@ let rfIgnore x = RuntimeFarkle.changePostProcessor PostProcessor.syntaxCheck x
110111
[<Tests>]
111112
let farkleGOLDGrammarEquivalenceTests =
112113
[
113-
"the calculator", rfIgnore SimpleMaths.int, "SimpleMaths.egt"
114-
"the F# JSON parser", rfIgnore JSON.FSharp.Language.runtime, "JSON.egt"
115-
"the C# JSON parser", rfIgnore JSON.CSharp.Language.Runtime, "JSON.egt"
116-
"the language of balanced parentheses", balancedParentheses, "balanced-parentheses.egt"
117-
"GOLD Meta-Language", rfIgnore GOLDMetaLanguage.runtime, "gml.egt"
114+
"the calculator", rfIgnore SimpleMaths.int, SimpleMaths.Definitions.Grammar.asBase64
115+
"the F# JSON parser", rfIgnore JSON.FSharp.Language.runtime, "./JSON.egt"
116+
"the C# JSON parser", rfIgnore JSON.CSharp.Language.Runtime, "./JSON.egt"
117+
"the language of balanced parentheses", balancedParentheses, "./balanced-parentheses.egt"
118+
"GOLD Meta-Language", rfIgnore GOLDMetaLanguage.runtime, "./gml.egt"
118119
]
119120
|> List.map (fun (name, gFarkle, egt) ->
120121
test (sprintf "Farkle and GOLD Parser generate an equivalent LALR parser for %s" name) {
121122
let gFarkle = extractGrammar gFarkle
122-
let gGold = loadGrammar egt
123+
let gGold =
124+
if egt.StartsWith("./") then
125+
loadGrammar egt
126+
else
127+
GOLDParser.EGT.ofBase64String egt
123128
checkParserEquivalence
124129
(gFarkle.Productions, gFarkle.LALRStates)
125130
(gGold.Productions, gGold.LALRStates)

Diff for: tests/Farkle.Tests/ParserTests.fs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open Farkle.IO
1313
open Farkle.JSON
1414
open Farkle.Parser
1515
open Farkle.Tests
16+
open SimpleMaths
1617
open System.IO
1718

1819
let logger = Log.create "Parser tests"

Diff for: tests/resources/SimpleMaths.egt

-1
This file was deleted.

0 commit comments

Comments
 (0)