Skip to content

Commit

Permalink
Merge pull request #286 from Eclalang/issue-#285-restructure-parser
Browse files Browse the repository at this point in the history
refactored parser node structure
  • Loading branch information
tot0p authored Feb 26, 2024
2 parents 3709243 + c6ff296 commit 77ef8a1
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 467 deletions.
79 changes: 79 additions & 0 deletions parser/decl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package parser

import "github.com/Eclalang/Ecla/lexer"

type FunctionDecl struct {
FunctionToken lexer.Token
Name string
Prototype FunctionPrototype
Body []Node
}

func (f FunctionDecl) StartPos() int {
return f.FunctionToken.Position
}

func (f FunctionDecl) EndPos() int {
return f.Prototype.RightBrace.Position
}

func (f FunctionDecl) StartLine() int {
return f.FunctionToken.Line
}

func (f FunctionDecl) EndLine() int {
return f.Prototype.RightBrace.Line
}

func (f FunctionDecl) declNode() {}

type StructDecl struct {
StructToken lexer.Token
Name string
LeftBrace lexer.Token
Fields []StructField
RightBrace lexer.Token
}

func (s StructDecl) StartPos() int {
return s.StructToken.Position
}

func (s StructDecl) EndPos() int {
return s.RightBrace.Position
}

func (s StructDecl) StartLine() int {
return s.StructToken.Line
}

func (s StructDecl) EndLine() int {
return s.RightBrace.Line
}

func (s StructDecl) declNode() {}

type VariableDecl struct {
VarToken lexer.Token
Name string
Type string
Value Expr
}

func (v VariableDecl) StartPos() int {
return v.VarToken.Position
}

func (v VariableDecl) EndPos() int {
return v.Value.EndPos()
}

func (v VariableDecl) StartLine() int {
return v.VarToken.Line
}

func (v VariableDecl) EndLine() int {
return v.Value.EndLine()
}

func (v VariableDecl) declNode() {}
Loading

0 comments on commit 77ef8a1

Please sign in to comment.