please help

This commit is contained in:
2024-08-10 16:49:47 +02:00
parent fec3c39de2
commit 459c7f47cd
6 changed files with 118 additions and 42 deletions
+60
View File
@@ -0,0 +1,60 @@
package parser
import (
"fmt"
"github.com/wyst-lang/wyst/tokenizer"
)
type inner interface {
isInner()
}
type Rule struct {
Name string
Inner inner
}
func (t Rule) String() string {
return fmt.Sprintf("AstRule(%s)", t.Name)
}
type Rules struct {
Value []Rule
}
func (v Rules) isInner() {}
type Token struct {
Value tokenizer.Rule
}
func (v Token) isInner() {}
type String struct {
Value string
}
func (v String) isInner() {}
type AstNode struct {
Rule Rule
Value string
Inner []AstNode
}
func (t AstNode) String() string {
return fmt.Sprintf("AstNode(\n rule=%s,\n value=%s,\n inner=%v\n)", t.Rule, t.Value, t.Inner)
}
// Ported rules from the tokenizer
var (
IDENTIFIER = Rule{"IDENTIFIER", Token{tokenizer.IDENTIFIER}}
)
var (
TOP = Rule{"TOP", Rules{
[]Rule{
IDENTIFIER,
}}}
)
+17
View File
@@ -0,0 +1,17 @@
package parser
import (
"github.com/wyst-lang/wyst/tokenizer"
)
func Parse(code string, rule Rule) ([]AstNode, tokenizer.State, error) {
tokens, state, _ := tokenizer.Tokenize(code)
var ast = []AstNode{}
for i := 0; i < len(tokens); i++ {
// token := tokens[i]
if rule.Inner == (String{""}) {
}
}
return ast, state, nil
}