diff --git a/expressions/parser.go b/expressions/parser.go index 714836f..322a639 100644 --- a/expressions/parser.go +++ b/expressions/parser.go @@ -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 } diff --git a/expressions/parser_test.go b/expressions/parser_test.go index 59cfeb6..5dc79b9 100644 --- a/expressions/parser_test.go +++ b/expressions/parser_test.go @@ -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) { diff --git a/expressions/y.go b/expressions/y.go index b3b14ca..94fec75 100644 --- a/expressions/y.go +++ b/expressions/y.go @@ -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 } diff --git a/parser/error.go b/parser/error.go index 2d22be7..b50e78c 100644 --- a/parser/error.go +++ b/parser/error.go @@ -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 diff --git a/parser/parser_test.go b/parser/parser_test.go index 426e2be..78393f7 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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 }{ diff --git a/render/blocks.go b/render/blocks.go index c814fc5..ce80c00 100644 --- a/render/blocks.go +++ b/render/blocks.go @@ -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 } } diff --git a/render/compiler_test.go b/render/compiler_test.go index b1016b1..d7482b5 100644 --- a/render/compiler_test.go +++ b/render/compiler_test.go @@ -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) { diff --git a/render/context_test.go b/render/context_test.go index 18a9577..41dd973 100644 --- a/render/context_test.go +++ b/render/context_test.go @@ -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"}, } diff --git a/tags/control_flow_tags.go b/tags/control_flow_tags.go index 55a076e..5db38cc 100644 --- a/tags/control_flow_tags.go +++ b/tags/control_flow_tags.go @@ -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 { diff --git a/tags/iteration_tags_test.go b/tags/iteration_tags_test.go index c90d453..66114d0 100644 --- a/tags/iteration_tags_test.go +++ b/tags/iteration_tags_test.go @@ -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 }{ diff --git a/tags/standard_tags_test.go b/tags/standard_tags_test.go index 8ac4c0a..33957d4 100644 --- a/tags/standard_tags_test.go +++ b/tags/standard_tags_test.go @@ -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"}, }