Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct comment parsing #1

Merged
merged 8 commits into from
Jul 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix parser
ysugimoto committed Jul 4, 2021
commit b038bda97d2408fcfed7aebafc58554ab82d6b41
19 changes: 19 additions & 0 deletions parser/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build ignore

package parser

import (
"fmt"

"github.com/k0kubun/pp"
)

// nolint: unused
func (p *Parser) debug(mark string) {
fmt.Printf("[%s] curToken: %s / peekToken: %s\n", mark, p.curToken, p.peekToken)
}

// nolint: unused
func (p *Parser) pp(v interface{}) {
pp.Println(v)
}
31 changes: 8 additions & 23 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@ import (
"fmt"
"strconv"
"strings"
_ "time"

"github.com/k0kubun/pp"
"github.com/pkg/errors"
"github.com/ysugimoto/falco/lexer"
"github.com/ysugimoto/falco/token"
@@ -59,16 +57,6 @@ type Parser struct {
infixParsers map[token.TokenType]infixParser
}

// nolint: unused
func (p *Parser) debug(mark string) {
fmt.Printf("[%s] curToken: %s / peekToken: %s\n", mark, p.curToken, p.peekToken)
}

// nolint: unused
func (p *Parser) pp(v interface{}) {
pp.Println(v)
}

func New(l *lexer.Lexer) *Parser {
p := &Parser{
l: l,
@@ -128,20 +116,16 @@ func (p *Parser) peekTokenIs(t token.TokenType) bool {
}

func (p *Parser) expectPeek(t token.TokenType) bool {
p.skipLineFeed()
for p.peekTokenIs(token.LF) {
p.nextToken()
}
if !p.peekTokenIs(t) {
return false
}
p.nextToken()
return true
}

func (p *Parser) skipLineFeed() {
for p.peekTokenIs(token.LF) {
p.nextToken()
}
}

func (p *Parser) comments(lv int) ast.Comments {
cs := ast.Comments{}

@@ -803,7 +787,7 @@ func (p *Parser) parseBlockStatement(nest int) (*ast.BlockStatement, error) {
stmt, err = p.parseSyntheticStatement(comments, nest)
case token.SYNTHETIC_BASE64:
p.nextToken()
stmt, err = p.parseSyntheticMeta64Statement(comments, nest)
stmt, err = p.parseSyntheticBase64Statement(comments, nest)
case token.IF:
p.nextToken()
stmt, err = p.parseIfStatement(comments, nest)
@@ -1138,6 +1122,7 @@ func (p *Parser) parseIfStatement(comments ast.Comments, nest int) (*ast.IfState
if err != nil {
return nil, errors.WithStack(err)
}
exp.Meta.Trailing = p.peekComments()
goto FINISH
case token.ELSEIF, token.ELSIF: // elseif, elsif
p.nextToken()
@@ -1148,10 +1133,10 @@ func (p *Parser) parseIfStatement(comments ast.Comments, nest int) (*ast.IfState
exp.Another = append(exp.Another, another)
continue
}
exp.Meta.Trailing = comments
goto FINISH
}
FINISH:
exp.Meta.Trailing = p.trailComment()
return exp, nil
}

@@ -1522,8 +1507,8 @@ func (p *Parser) parseSyntheticStatement(comments ast.Comments, nest int) (*ast.
return stmt, nil
}

func (p *Parser) parseSyntheticMeta64Statement(comments ast.Comments, nest int) (*ast.SyntheticMeta64Statement, error) {
stmt := &ast.SyntheticMeta64Statement{
func (p *Parser) parseSyntheticBase64Statement(comments ast.Comments, nest int) (*ast.SyntheticBase64Statement, error) {
stmt := &ast.SyntheticBase64Statement{
Meta: ast.New(p.curToken, nest, comments),
}

Loading
Oops, something went wrong.