aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spec/parser.go8
-rw-r--r--spec/parser_test.go54
-rw-r--r--spec/syntax_error.go2
3 files changed, 62 insertions, 2 deletions
diff --git a/spec/parser.go b/spec/parser.go
index 9c66bfb..efbd072 100644
--- a/spec/parser.go
+++ b/spec/parser.go
@@ -494,10 +494,14 @@ func (p *parser) parseParameter() *ParameterNode {
Group: g,
Pos: pos,
}
- default:
- return nil
}
if p.consume(tokenKindExpantion) {
+ switch {
+ case param == nil:
+ raiseSyntaxError(p.pos.Row, synErrStrayExpOp)
+ case param.ID == "":
+ raiseSyntaxError(p.pos.Row, synErrInvalidExpOperand)
+ }
param.Expansion = true
}
return param
diff --git a/spec/parser_test.go b/spec/parser_test.go
index 15f1330..c7d43de 100644
--- a/spec/parser_test.go
+++ b/spec/parser_test.go
@@ -599,6 +599,60 @@ bar: "bar";
},
},
{
+ caption: "an expansion operator must be preceded by an identifier",
+ src: `
+s
+ : foo #ast ...
+ ;
+`,
+ synErr: synErrStrayExpOp,
+ },
+ {
+ caption: "an expansion operator must be preceded by an identifier",
+ src: `
+a
+ : foo #ast ... foo
+ ;
+`,
+ synErr: synErrStrayExpOp,
+ },
+ {
+ caption: "an expansion operator cannot be applied to a pattern",
+ src: `
+a
+ : "foo" #ast "foo"...
+ ;
+`,
+ synErr: synErrInvalidExpOperand,
+ },
+ {
+ caption: "an expansion operator cannot be applied to a string",
+ src: `
+a
+ : 'foo' #ast 'foo'...
+ ;
+`,
+ synErr: synErrInvalidExpOperand,
+ },
+ {
+ caption: "an expansion operator cannot be applied to an ordered symbol",
+ src: `
+a
+ : foo #ast $foo...
+ ;
+`,
+ synErr: synErrInvalidExpOperand,
+ },
+ {
+ caption: "an expansion operator cannot be applied to a directive group",
+ src: `
+a
+ : foo #ast ()...
+ ;
+`,
+ synErr: synErrInvalidExpOperand,
+ },
+ {
caption: "an AST has node positions",
src: `
exp
diff --git a/spec/syntax_error.go b/spec/syntax_error.go
index cf64e75..db4c381 100644
--- a/spec/syntax_error.go
+++ b/spec/syntax_error.go
@@ -37,6 +37,8 @@ var (
synErrNoDirectiveName = newSyntaxError("a directive needs a name")
synErrNoOrderedSymbolName = newSyntaxError("an ordered symbol name is missing")
synErrUnclosedDirGroup = newSyntaxError("a directive group must be closed by )")
+ synErrStrayExpOp = newSyntaxError("an expansion operator ... must be preceded by an identifier")
+ synErrInvalidExpOperand = newSyntaxError("an expansion operator ... can be applied to only an identifier")
synErrSemicolonNoNewline = newSyntaxError("a semicolon must be followed by a newline")
synErrFragmentNoPattern = newSyntaxError("a fragment needs one pattern element")
)