12345678910111213141516171819202122232425262728293031323334353637 |
- package ast
- // Node is the interface implemented by every node in the AST.
- type Node interface {
- // TokenLiteral returns the literal value of the token it's associated to.
- TokenLiteral() string
- }
- // Statement extends Node and is only a way to differentiate between expressions
- // and statements.
- type Statement interface {
- Node
- statementNode()
- }
- // Expression extends Node and is only a way to differentiate between
- // expressions and statements.
- type Expression interface {
- // Expression extends Node.
- Node
- expressionNode()
- }
- // Program represents the outer structure of the parser program.
- type Program struct {
- Statements []Statement
- }
- // TokenLiteral returns the string contents of the first statement token, which
- // can be an empty string if the program is empty.
- func (p *Program) TokenLiteral() string {
- if len(p.Statements) > 0 {
- return p.Statements[0].TokenLiteral()
- }
- return ""
- }
|