Skip to content

Commit c5f51dd

Browse files
author
Clancy
committed
refactor(parser to schema): implement precise boundary parsing and decouple resolver pipeline
1- Introduce a delimiter stack in the parser to track open parentheses, brackets,..etc to track their exact source positions for comprehensive err msgs instead of generic token mismatches 2- Add immediate parsing checks for top-level block keywords during field parsing to detect missing closing braces and improve error recovery block transitions 3- Restructure parser entry points into ParseAST() to pass the AST to the resolver 4- Add ultimate integration test
1 parent c49e8c3 commit c5f51dd

14 files changed

Lines changed: 3242 additions & 695 deletions

‎.gitignore‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
*.exe
21
.env
3-
*.md
2+
*.md

‎main.go‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7-
"valkyrie/parser"
7+
"valkyrie/schema"
88
)
99

1010
func main() {
1111

12-
file, err := os.ReadFile("schema.prisma")
13-
if err != nil {
14-
panic(err)
15-
}
16-
tokens := parser.ExtractTokens(string(file))
17-
parser.LogTokens(tokens)
18-
parser := parser.Parser{
19-
Tokens: tokens,
20-
Pos: 0,
12+
fileBytes, _ := os.ReadFile("schema.prisma")
13+
rawString := string(fileBytes)
14+
15+
// tokens := schema.ExtractTokens(rawString)
16+
// for i, token := range tokens {
17+
// fmt.Printf("%d: %+v\n", i, token)
18+
// }
19+
20+
schema, errs := schema.ParseSchema(rawString)
21+
if len(errs) > 0 {
22+
for _, err := range errs {
23+
fmt.Println(err)
24+
}
25+
2126
}
22-
b, _ := json.MarshalIndent(parser.Parse(), "", " ")
27+
28+
b, _ := json.MarshalIndent(schema, "", " ")
29+
30+
os.WriteFile("result.json", b, 0644)
2331
fmt.Println(string(b))
2432
}

‎mindmap.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Lexer produces tokens
2+
Tokens are passed to parser which produces an AST
3+
AST is passed to resolver which produces a schema (or the IR)
4+
IR will be passed to do codegen and construct migrations

‎parser/parser.go‎

Lines changed: 0 additions & 338 deletions
This file was deleted.

0 commit comments

Comments
 (0)