1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 07:38:59 +01:00

Rename parse error -> syntax error

This commit is contained in:
Oliver Steele 2017-07-18 18:39:38 -04:00
parent a78d95d73f
commit 7af399ae6f
11 changed files with 30 additions and 30 deletions

View File

@ -14,11 +14,11 @@ type parseValue struct {
val func(Context) interface{}
}
// ParseError represents a parse error. The yacc-generated compiler
// SyntaxError represents a syntax error. The yacc-generated compiler
// doesn't use error returns; this lets us recognize them.
type ParseError string
type SyntaxError string
func (e ParseError) Error() string { return string(e) }
func (e SyntaxError) Error() string { return string(e) }
// Parse parses an expression string into an Expression.
func Parse(source string) (expr Expression, err error) {
@ -33,7 +33,7 @@ func parse(source string) (p *parseValue, err error) {
defer func() {
if r := recover(); r != nil {
switch e := r.(type) {
case ParseError:
case SyntaxError:
err = e
case UndefinedFilter:
err = e
@ -46,7 +46,7 @@ func parse(source string) (p *parseValue, err error) {
lex := newLexer([]byte(source + ";"))
n := yyParse(lex)
if n != 0 {
return nil, ParseError(fmt.Errorf("parse error in %q", source).Error())
return nil, SyntaxError(fmt.Errorf("syntax error in %q", source).Error())
}
return &lex.parseValue, nil
}

View File

@ -15,12 +15,12 @@ var parseTests = []struct {
}
var parseErrorTests = []struct{ in, expected string }{
{"a syntax error", "parse error"},
{`%assign a`, "parse error"},
{`%assign a 3`, "parse error"},
{`%cycle 'a' 'b'`, "parse error"},
{`%loop a in in`, "parse error"},
{`%when a b`, "parse error"},
{"a syntax error", "syntax error"},
{`%assign a`, "syntax error"},
{`%assign a 3`, "syntax error"},
{`%cycle 'a' 'b'`, "syntax error"},
{`%loop a in in`, "syntax error"},
{`%when a b`, "syntax error"},
}
func TestParse(t *testing.T) {

View File

@ -626,7 +626,7 @@ yydefault:
{
s, ok := yyDollar[1].val.(string)
if !ok {
panic(ParseError(fmt.Sprintf("expected a string for %q", yyDollar[1].val)))
panic(SyntaxError(fmt.Sprintf("expected a string for %q", yyDollar[1].val)))
}
yyVAL.s = s
}
@ -671,7 +671,7 @@ yydefault:
case "reversed":
yyDollar[1].loopmods.Reversed = true
default:
panic(ParseError(fmt.Sprintf("undefined loop modifier %q", yyDollar[2].name)))
panic(SyntaxError(fmt.Sprintf("undefined loop modifier %q", yyDollar[2].name)))
}
yyVAL.loopmods = yyDollar[1].loopmods
}
@ -683,23 +683,23 @@ yydefault:
case "cols":
cols, ok := yyDollar[3].val.(int)
if !ok {
panic(ParseError(fmt.Sprintf("loop cols must an integer")))
panic(SyntaxError(fmt.Sprintf("loop cols must an integer")))
}
yyDollar[1].loopmods.Cols = cols
case "limit":
limit, ok := yyDollar[3].val.(int)
if !ok {
panic(ParseError(fmt.Sprintf("loop limit must an integer")))
panic(SyntaxError(fmt.Sprintf("loop limit must an integer")))
}
yyDollar[1].loopmods.Limit = &limit
case "offset":
offset, ok := yyDollar[3].val.(int)
if !ok {
panic(ParseError(fmt.Sprintf("loop offset must an integer")))
panic(SyntaxError(fmt.Sprintf("loop offset must an integer")))
}
yyDollar[1].loopmods.Offset = offset
default:
panic(ParseError(fmt.Sprintf("undefined loop modifier %q", yyDollar[2].name)))
panic(SyntaxError(fmt.Sprintf("undefined loop modifier %q", yyDollar[2].name)))
}
yyVAL.loopmods = yyDollar[1].loopmods
}

View File

@ -2,7 +2,7 @@ package parser
import "fmt"
// An Error is a parse error during template parsing.
// An Error is a syntax error during template parsing.
type Error interface {
error
Cause() error

View File

@ -32,8 +32,8 @@ var parseErrorTests = []struct{ in, expected string }{
{"{% if test %}", `unterminated "if" block`},
{"{% if test %}{% endunless %}", "not inside unless"},
// TODO tag syntax could specify statement type to catch these in parser
// {"{{ syntax error }}", "parse error"},
// {"{% for syntax error %}{% endfor %}", "parse error"},
// {"{{ syntax error }}", "syntax error"},
// {"{% for syntax error %}{% endfor %}", "syntax error"},
}
var parserTests = []struct{ in string }{

View File

@ -111,7 +111,7 @@ func (b blockDefBuilder) Compiler(fn BlockCompiler) {
// Renderer sets the render action for a control tag definition.
func (b blockDefBuilder) Renderer(fn func(io.Writer, Context) error) {
b.tag.parser = func(node BlockNode) (func(io.Writer, Context) error, error) {
// TODO parse error if there are arguments?
// TODO syntax error if there are arguments?
return fn, nil
}
}

View File

@ -19,7 +19,7 @@ var compilerErrorTests = []struct{ in, expected string }{
{`{% unknown_tag %}`, "unknown tag"},
{`{% block %}{% endblock %}`, "block compiler error"},
// {`{% tag %}`, "tag compiler error"},
// {`{%for syntax error%}{%endfor%}`, "parse error"},
// {`{%for syntax error%}{%endfor%}`, "syntax error"},
}
func TestCompileErrors(t *testing.T) {

View File

@ -75,8 +75,8 @@ func TestContext(t *testing.T) {
}
var contextErrorTests = []struct{ in, expect string }{
{`{% test_evaluate_string syntax error %}`, "parse error"},
{`{% test_expand_tag_arg {{ syntax error }} %}`, "parse error"},
{`{% test_evaluate_string syntax error %}`, "syntax error"},
{`{% test_expand_tag_arg {{ syntax error }} %}`, "syntax error"},
{`{% test_expand_tag_arg {{ x | undefined_filter }} %}`, "undefined filter"},
}

View File

@ -39,7 +39,7 @@ func (c elseCase) body() *render.BlockNode { return c.b }
func (c elseCase) test(interface{}, render.Context) (bool, error) { return true, nil }
func caseTagCompiler(node render.BlockNode) (func(io.Writer, render.Context) error, error) {
// TODO parse error on non-empty node.Body
// TODO syntax error on non-empty node.Body
expr, err := e.Parse(node.Args)
if err != nil {
return nil, err
@ -95,7 +95,7 @@ func ifTagCompiler(polarity bool) func(render.BlockNode) (func(io.Writer, render
test := e.Constant(true)
switch c.Name {
case "else":
// TODO parse error if this isn't the last branch
// TODO syntax error if this isn't the last branch
case "elsif":
t, err := e.Parse(c.Args)
if err != nil {

View File

@ -91,9 +91,9 @@ var iterationTests = []struct{ in, expected string }{
}
var iterationSyntaxErrorTests = []struct{ in, expected string }{
{`{% for a b c %}{% endfor %}`, "parse error"},
{`{% for a b c %}{% endfor %}`, "syntax error"},
{`{% for a in array offset %}{% endfor %}`, "undefined loop modifier"},
{`{% cycle %}`, "parse error"},
{`{% cycle %}`, "syntax error"},
}
var iterationErrorTests = []struct{ in, expected string }{

View File

@ -13,10 +13,10 @@ import (
var parseErrorTests = []struct{ in, expected string }{
{"{% unknown_tag %}", "unknown tag"},
{"{% assign v x y z %}", "parse error"},
{"{% assign v x y z %}", "syntax error"},
{"{% if syntax error %}", `unterminated "if" block`},
// TODO once expression parsing is moved to template parse stage
// {"{% if syntax error %}{% endif %}", "parse error"},
// {"{% if syntax error %}{% endif %}", "syntax error"},
// {"{% for a in ar unknown %}{{ a }} {% endfor %}", "TODO"},
}