Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
You can update snaphshots with the
`UPDATE_SNAPS=true` variable while running the tests

If you need to update the grammar, you can generate the parser by running `just generate` (you'll need to install the antlr4 command first)
The Numscript parser (`internal/parser`) is hand-written, so that it can recover from syntax errors: the LSP needs a meaningful AST for programs that are being typed. The [Numscript.g4](Numscript.g4) and [Lexer.g4](Lexer.g4) grammars are still the reference for the syntax, and they generate the previous, ANTLR-based parser (`internal/parser/internal/legacy`). The tests check that both parsers agree on every program of the repository, so if you change the syntax, update both the hand-written parser and the grammar.

You can generate the ANTLR parsers by running `just generate` (you'll need to install the antlr4 command first)
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ tidy:
@go mod tidy

generate:
@antlr4 -Dlanguage=Go Lexer.g4 Numscript.g4 -o internal/parser/antlrParser -package antlrParser
@mv internal/parser/antlrParser/_lexer.go internal/parser/antlrParser/lexer.go
@antlr4 -Dlanguage=Go Lexer.g4 Numscript.g4 -o internal/parser/internal/legacy/antlrParser -package antlrParser
@mv internal/parser/internal/legacy/antlrParser/_lexer.go internal/parser/internal/legacy/antlrParser/lexer.go
@antlr4 -Dlanguage=Go IR.g4 -o internal/ir/internal/syntax/antlrParser -package antlrParser

tests:
Expand Down
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ignore:
- "internal/parser/antlrParser"
- "internal/parser/internal/legacy"
- "internal/ir/internal/syntax/antlrParser"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/pretty v0.3.1
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.9.2 // indirect
github.com/maruel/natural v1.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions internal/analysis/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (r *CheckResult) GetVarDeclType(decl parser.VarDeclaration) Type {
}

func (r *CheckResult) unifyNodeWith(expr parser.ValueExpr, t Type) {
if expr == nil {
// a missing node of an incomplete program
return
}
exprT := r.GetExprType(expr)
r.unify(expr.GetRange(), exprT, t)
}
Expand Down
Loading
Loading