Skip to content

Commit

Permalink
start to build out parser
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jul 27, 2020
1 parent 12a18a5 commit c209bd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 4 additions & 5 deletions processor/parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package parser

import "fmt"

type Expr struct {
Op string
Left *Expr
Expand All @@ -19,7 +17,7 @@ func NewParser(lexer Lexer) Parser {
}
}

func (p *Parser) Parse() {
func (p *Parser) Parse() *Expr {
tokens := p.lexer.Tokens()

for _, t := range tokens {
Expand All @@ -30,7 +28,8 @@ func (p *Parser) Parse() {
Val: t.Value,
}

fmt.Println(t)
fmt.Println(p)
return &p
}

return nil
}
25 changes: 24 additions & 1 deletion processor/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@ package parser

import "testing"


func TestParser_Empty(t *testing.T) {
lex := NewLexer(``)
parser := NewParser(lex)
expr := parser.Parse()

if expr != nil {
t.Error("expected nil")
}
}


func TestParser_Parse(t *testing.T) {
lex := NewLexer(`test`)
parser := NewParser(lex)
expr := parser.Parse()

if expr == nil {
t.Error("should be something")
}

if expr.Op != "TERM" {
t.Error("expected TERM got", expr.Op)
}

parser.Parse()
if expr.Val != "test" {
t.Error("expected test got", expr.Val)
}
}

0 comments on commit c209bd4

Please sign in to comment.