Skip to content

Commit

Permalink
Switch to New Parser in Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
iwillspeak committed Jun 18, 2023
1 parent 0f20c8b commit 7c274b4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 298 deletions.
20 changes: 9 additions & 11 deletions src/Feersum.CompilerServices/Compile/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ module private Utils =
il.Emit(OpCodes.Ret)

module Compilation =
open Feersum.CompilerServices.Syntax.Parse

/// Emit a Bound Expression to .NET
///
Expand Down Expand Up @@ -1214,17 +1215,14 @@ module Compilation =
else
output

let ast, diagnostics =
let nodes, diagnostics =
List.map LegacyParse.parseFile sources
|> List.fold (fun (nodes, diags) (n, d) -> (List.append nodes [ n ], List.append d diags)) ([], [])
let result =
Seq.map (Parse.parseFile) sources
|> Async.Parallel
|> Async.RunSynchronously
|> ParseResult.fold (fun (progs) (p) -> List.append progs [ p ]) []

{ Location = TextLocation.Missing
Kind = AstNodeKind.Seq(nodes) },
diagnostics

if Diagnostics.hasErrors diagnostics then
diagnostics
if Diagnostics.hasErrors result.Diagnostics then
result.Diagnostics
else

// Open the output streams. We don't use an `Option` directly here for
Expand All @@ -1238,7 +1236,7 @@ module Compilation =
| BuildConfiguration.Release -> null

let result =
compile options outputStream (Path.GetFileName(output)) (symbols |> Option.ofObj) ast
compile options outputStream (Path.GetFileName(output)) (symbols |> Option.ofObj) result.Root

if result.Diagnostics.IsEmpty && options.OutputType = OutputType.Exe then
match result.EmittedAssemblyName with
Expand Down
2 changes: 0 additions & 2 deletions src/Feersum.CompilerServices/Feersum.CompilerServices.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
<Compile Include="Options.fs" />
<Compile Include="Text.fs" />
<Compile Include="Diagnostics.fs" />
<Compile Include="LegacySyntax.fs" />
<Compile Include="Syntax/Lex.fs" />
<Compile Include="Syntax/Tree.fs" />
<Compile Include="Syntax/Parse.fs" />
<Compile Include="Syntax/SyntaxShim.fs" />
<Compile Include="Scope.fs" />
<Compile Include="Binding/Libraries.fs" />
<Compile Include="Binding/Macros.fs" />
Expand Down
258 changes: 0 additions & 258 deletions src/Feersum.CompilerServices/LegacySyntax.fs

This file was deleted.

7 changes: 7 additions & 0 deletions src/Feersum.CompilerServices/Syntax/Parse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ module ParseResult =
{ Diagnostics = result.Diagnostics
Root = result.Root |> mapper }

/// Fold a set of parse results into a signle result
let public fold folder seed results =
let (state, diags) =
Seq.fold (fun (state, diags) r -> (folder state r.Root, List.append diags r.Diagnostics)) (seed, []) results
{ Diagnostics = diags
Root = state }

/// Convert a parser response into a plain result type
///
/// This drops any tree from the error, but opens up parser responses to
Expand Down
27 changes: 0 additions & 27 deletions src/Feersum.CompilerServices/Syntax/SyntaxShim.fs

This file was deleted.

0 comments on commit 7c274b4

Please sign in to comment.