70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package parser
|
|
|
|
import "git.sharkk.net/Sharkk/Mako/lexer"
|
|
|
|
type Node interface {
|
|
TokenLiteral() string
|
|
}
|
|
|
|
type Statement interface {
|
|
Node
|
|
statementNode()
|
|
}
|
|
|
|
type Expression interface {
|
|
Node
|
|
expressionNode()
|
|
}
|
|
|
|
type Program struct {
|
|
Statements []Statement
|
|
}
|
|
|
|
func (p *Program) TokenLiteral() string {
|
|
if len(p.Statements) > 0 {
|
|
return p.Statements[0].TokenLiteral()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type VariableStatement struct {
|
|
Token lexer.Token
|
|
Name *Identifier
|
|
Value Expression
|
|
}
|
|
|
|
func (vs *VariableStatement) statementNode() {}
|
|
func (vs *VariableStatement) TokenLiteral() string { return vs.Token.Value }
|
|
|
|
type EchoStatement struct {
|
|
Token lexer.Token
|
|
Value Expression
|
|
}
|
|
|
|
func (es *EchoStatement) statementNode() {}
|
|
func (es *EchoStatement) TokenLiteral() string { return es.Token.Value }
|
|
|
|
type Identifier struct {
|
|
Token lexer.Token
|
|
Value string
|
|
}
|
|
|
|
func (i *Identifier) expressionNode() {}
|
|
func (i *Identifier) TokenLiteral() string { return i.Token.Value }
|
|
|
|
type StringLiteral struct {
|
|
Token lexer.Token
|
|
Value string
|
|
}
|
|
|
|
func (sl *StringLiteral) expressionNode() {}
|
|
func (sl *StringLiteral) TokenLiteral() string { return sl.Token.Value }
|
|
|
|
type NumberLiteral struct {
|
|
Token lexer.Token
|
|
Value float64
|
|
}
|
|
|
|
func (nl *NumberLiteral) expressionNode() {}
|
|
func (nl *NumberLiteral) TokenLiteral() string { return nl.Token.Value }
|