Skip to content

Commit e022b90

Browse files
committed
fix: tests all working
1 parent 1c6512e commit e022b90

File tree

5 files changed

+21
-37
lines changed

5 files changed

+21
-37
lines changed

pkg/ast/ast.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ast
22

33
import (
44
"bytes"
5+
"fmt"
56

67
"github.com/dnitsch/async-api-generator/pkg/token"
78
)
@@ -64,7 +65,7 @@ func (ls *GenDocStatement) String() string {
6465
var out bytes.Buffer
6566

6667
out.WriteString(ls.TokenLiteral())
67-
out.WriteString(ls.Name.String())
68+
out.WriteString(fmt.Sprintf("%s %s", ls.Name.String(), ls.Token.MetaTags))
6869

6970
if ls.Value != nil {
7071
out.WriteString(ls.Value.String())

pkg/ast/ast_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ func TestString(t *testing.T) {
2222
},
2323
},
2424
&ast.GenDocStatement{
25-
Token: token.Token{Type: token.BEGIN_DOC_GEN, Literal: "// gendoc"},
25+
Token: token.Token{Type: token.BEGIN_DOC_GEN, Literal: "// gendoc", MetaTags: "type=message,subtype=example,consumer=[],producer=[]"},
2626
Name: &ast.EnclosedIdentifier{
27-
Token: token.Token{Type: token.TEXT, Literal: ""},
27+
Token: token.Token{Type: token.CONTENT_DOC_GEN, Literal: "content_gendoc"},
2828
Value: "",
2929
},
3030
Value: &ast.EnclosedIdentifier{
31-
Token: token.Token{Type: token.NEW_LINE, Literal: "gendoc"},
32-
Value: " type=message,subtype=example,consumer=[],producer=[]",
31+
Token: token.Token{Type: token.TEXT, Literal: "text"},
32+
Value: "", //
3333
},
3434
},
3535
},

pkg/parser/parser.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const (
2020
INDEX // array[index]
2121
)
2222

23-
var precedences = map[token.TokenType]int{}
24-
2523
type Parser struct {
2624
l *lexer.Lexer
2725
errors []string
@@ -102,6 +100,8 @@ func (p *Parser) parseStatement() ast.Statement {
102100

103101
func (p *Parser) parseBeginGenDocStatement() *ast.GenDocStatement {
104102
stmt := &ast.GenDocStatement{Token: p.curToken}
103+
// do some parsing here perhaps of the name and file name/location etc...
104+
stmt.Name = &ast.EnclosedIdentifier{Token: token.Token{Type: token.BEGIN_DOC_GEN, Literal: "// gendoc", MetaTags: p.curToken.MetaTags}, Value: "// gendoc"} //p.curToken.MetaTags}
105105
// move past gendoc token
106106
p.nextToken()
107107

@@ -115,8 +115,8 @@ func (p *Parser) parseBeginGenDocStatement() *ast.GenDocStatement {
115115
}
116116
p.nextToken()
117117
}
118-
119-
stmt.Value = &ast.EnclosedIdentifier{token.Token{token.CONTENT_DOC_GEN, genDocValue, stmt.Token.MetaTags}, genDocValue}
118+
119+
stmt.Value = &ast.EnclosedIdentifier{Token: token.Token{Type: token.CONTENT_DOC_GEN, Literal: genDocValue, MetaTags: stmt.Token.MetaTags}, Value: genDocValue}
120120
// skip end doc
121121
p.nextToken()
122122
return stmt
@@ -129,31 +129,14 @@ func (p *Parser) parseIgnoreStatement() *ast.IgnoreStatement {
129129
for !p.curTokenIs(token.EOF) {
130130
ignoreValue += p.curToken.Literal
131131
if p.peekTokenIs(token.BEGIN_DOC_GEN) {
132-
p.nextToken()
133132
break
134133
}
135134
p.nextToken()
136135
}
137-
stmt.Value = &ast.UnusedIdentifier{token.Token{Type: token.NEW_LINE, Literal: ignoreValue}, ignoreValue}
136+
stmt.Value = &ast.UnusedIdentifier{Token: token.Token{Type: token.NEW_LINE, Literal: ignoreValue}, Value: ignoreValue}
138137
return stmt
139138
}
140139

141140
func (p *Parser) parseExpression(precedence int) ast.Expression {
142141
return &ast.EnclosedIdentifier{}
143142
}
144-
145-
func (p *Parser) peekPrecedence() int {
146-
if p, ok := precedences[p.peekToken.Type]; ok {
147-
return p
148-
}
149-
150-
return LOWEST
151-
}
152-
153-
func (p *Parser) curPrecedence() int {
154-
if p, ok := precedences[p.curToken.Type]; ok {
155-
return p
156-
}
157-
158-
return LOWEST
159-
}

pkg/parser/parser_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stuff {
2020
here string
2121
}
2222
// !gendoc
23-
`, "gendoc", `stuff {
23+
`, "// gendoc", `stuff {
2424
here string
2525
}`},
2626
// "bool": {"let y = true;", "y", true},
@@ -46,25 +46,25 @@ stuff {
4646
}
4747

4848
func testGenDocStatement(t *testing.T, s ast.Statement, name string) bool {
49-
if s.TokenLiteral() != "gendoc" {
50-
t.Errorf("got=%q, wanted s.TokenLiteral = 'gendoc'.", s.TokenLiteral())
49+
if s.TokenLiteral() != "// gendoc" {
50+
t.Errorf("got=%q, wanted s.TokenLiteral = '// gendoc'.", s.TokenLiteral())
5151
return false
5252
}
5353

54-
letStmt, ok := s.(*ast.GenDocStatement)
54+
genStmt, ok := s.(*ast.GenDocStatement)
5555
if !ok {
5656
t.Errorf("s not *ast.GenDocStatement. got=%T", s)
5757
return false
5858
}
5959

60-
if letStmt.Name.Value != name {
61-
t.Errorf("letStmt.Name.Value not '%s'. got=%s", name, letStmt.Name.Value)
60+
if genStmt.Name.Value != name {
61+
t.Errorf("letStmt.Name.Value not '%s'. got=%s", name, genStmt.Name.Value)
6262
return false
6363
}
6464

65-
if letStmt.Name.TokenLiteral() != name {
65+
if genStmt.Name.TokenLiteral() != name {
6666
t.Errorf("letStmt.Name.TokenLiteral() not '%s'. got=%s",
67-
name, letStmt.Name.TokenLiteral())
67+
name, genStmt.Name.TokenLiteral())
6868
return false
6969
}
7070

pkg/token/token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ type TokenType string
55
const (
66
ILLEGAL TokenType = "ILLEGAL"
77
EOF TokenType = "EOF"
8-
8+
99
SPACE TokenType = "SPACE" // ' '
1010
TAB TokenType = "TAB" // '\t'
1111
NEW_LINE TokenType = "NEW_LINE" // '\n'
1212
CARRIAGE_RETURN TokenType = "CARRIAGE_RETURN" // '\r'
1313
CONTROL TokenType = "CONTROL"
14-
14+
1515
// Identifiers + literals
1616
TEXT TokenType = "TEXT" //
1717
CONTENT_DOC_GEN TokenType = "CONTENT_DOC_GEN" //

0 commit comments

Comments
 (0)