Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to New Parser #55

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Switch to New Parser #55

wants to merge 15 commits into from

Conversation

iwillspeak
Copy link
Owner

@iwillspeak iwillspeak commented Jun 12, 2022

Bringing the new parser up to speed. Replacing all uses of the old parser with the new one, and
binning the old parser.

TODO:

  • Compiler
  • Binder
  • Macros
  • Libraries
  • tests

@@ -1234,7 +1234,7 @@ module Compilation =

let ast, diagnostics =
let nodes, diagnostics =
List.map Parse.parseFile sources
List.map LegacyParse.parseFile sources
|> List.fold (fun (nodes, diags) (n, d) -> (List.append nodes [ n ], List.append d diags)) ([], [])

{ Location = TextLocation.Missing
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to come up with a better way of modelling this. The previous parser was run on each input, and then we pasted them together into a single big SEQ. Instead I guess we should have a wrapper Compilation type, which contains a set of BoundCompilationUnits. We can bind them in sequence, and propagate some state (lib definitions etc.). The key is we don't want to have public items from one unit just become 'magically' available in another. This will probably want to be different for script compilations however. In that case we'd want multiple passes at compilation to share definitions from the previous.

We may want to handle this by just having the last compilation unit in the compilation be treated specially and allow definitions from that to leak into the root binder scope. That way inherited compilations from scripting would have access to the previous definitions.

src/Feersum.CompilerServices/Syntax/Parse.fs Outdated Show resolved Hide resolved
ReadLine.Read("[]> ")
|> Parse.readProgram "repl.scm"

let private print (result: ParseResult<Program>) =
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some kind of ast explorer which allows you to cd and ls around the tree might be nice.

@iwillspeak
Copy link
Owner Author

@@ -6,6 +6,14 @@ open Feersum.CompilerServices.Diagnostics
open Feersum.CompilerServices.Syntax
open Feersum.CompilerServices.Utils

module private BinderDiagnostics =

// TODO: remove this and replace with better binder errors
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Distinct binder diagnostics.

ctx.Diagnostics.Emit
BinderDiagnostics.bindError
(List.last formals).Location
"Saw dot but no ID in formals"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dots should be handled by the parse, not the bind

match node.Kind with
| AstNodeKind.Ident i -> BoundDatum.Ident i
| AstNodeKind.Constant c -> BoundDatum.SelfEval(BoundLiteral.FromConstant c)
| AstNodeKind.Dot -> BoundDatum.Ident "." // FIXME: This is definitely not right
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix me. Datum dots.

inherit Expression(red)

member public _.OpeningParen =
red.ChildrenWithTokens()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should / could lazies work here?

if s.Line = e.Line then
sprintf
"%s(%d,%d-%d): %s: %s"
(s.Source |> normaliseName)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks click through and problem matching in VS Code. Maybe Code needs a PR?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwillspeak iwillspeak force-pushed the feature/newparse-full branch from 2ccc457 to 309f86c Compare September 2, 2022 07:20
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch 3 times, most recently from f49cb8a to de9feb9 Compare June 17, 2023 17:56
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch from de9feb9 to 7c274b4 Compare June 18, 2023 09:44
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch 2 times, most recently from 9d1b6f8 to 9df82a1 Compare July 29, 2023 13:49
@iwillspeak iwillspeak changed the base branch from main to feature/macnew June 17, 2024 07:45
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch 2 times, most recently from ac7f645 to 67b8269 Compare June 18, 2024 06:35
@iwillspeak iwillspeak changed the base branch from feature/macnew to main June 18, 2024 06:35
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch 2 times, most recently from 4aede6a to 27dd7a0 Compare June 21, 2024 08:23
Compilations are now run on `CompileInput`s containing either a
`Program` or `ScriptProgram`. This is then lowered to a legacy tree for
binding but should allow compile API surface changes to be fleshed out.

Some `eval` tests working directly with legacy trees may benefit from
a syntax builder API.
Fixes a bug where trailing junk would not be identified as an error
in parsing.
Sketching out the structure of syntax factories. These now need
implementing for the remaining node types.

Heavily inspired by `Teasel`'s `SyntaxFactory` work.
Factory for bool nodes.
Update the REPL to allow statements to cross lines.
Introduce factories for string and character values. This should mean we
now have all the main constant types covered.
Bring back some of the `EvalTests` by adding in factories for our root
program types.
Add factory support for quoted values.
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch from 1565ddb to 0a758ad Compare June 22, 2024 09:18
Introduce the form and symbol factories, and use them to implement the
remaining disabled `eval` tests.
Rather than relying on dup and storing the value on the statck while we
perform the `#f` check we can instead store the temporary value in a
local. This simplifies the codepath for the `true` case.
@iwillspeak iwillspeak force-pushed the feature/newparse-full branch from 0a758ad to 4be1099 Compare June 22, 2024 16:50
These files are getting unwieldly and unreadable when embedded in json.
Update the assertions to read them from disk instead.
"
ATMOSPHERE: (98..162) ";; exporting or re-exporting macro definitions currently."
ATMOSPHERE: (162..167) "
"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to teach Firethorn some escapes?

Upgrade to the latest versions of most packages. This includes a breaking
change to the debug output of `Firethorn` so test needed re-generating
too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant