aboutsummaryrefslogtreecommitdiff
path: root/spec/syntax_error.go
diff options
context:
space:
mode:
Diffstat (limited to 'spec/syntax_error.go')
-rw-r--r--spec/syntax_error.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/syntax_error.go b/spec/syntax_error.go
new file mode 100644
index 0000000..815b38f
--- /dev/null
+++ b/spec/syntax_error.go
@@ -0,0 +1,32 @@
+package spec
+
+import "fmt"
+
+type SyntaxError struct {
+ message string
+}
+
+func newSyntaxError(message string) *SyntaxError {
+ return &SyntaxError{
+ message: message,
+ }
+}
+
+func (e *SyntaxError) Error() string {
+ return fmt.Sprintf("syntax error: %s", e.message)
+}
+
+var (
+ // lexical errors
+ synErrUnclosedTerminal = newSyntaxError("unclosed terminal")
+ synErrInvalidEscSeq = newSyntaxError("invalid escape sequence")
+ synErrIncompletedEscSeq = newSyntaxError("incompleted escape sequence; unexpected EOF following \\")
+
+ // syntax errors
+ synErrInvalidToken = newSyntaxError("invalid token")
+ synErrNoProduction = newSyntaxError("a grammar must have at least one production")
+ synErrNoProductionName = newSyntaxError("a production name is missing")
+ synErrNoColon = newSyntaxError("the colon must precede alternatives")
+ synErrNoSemicolon = newSyntaxError("the semicolon is missing at the last of an alternative")
+ synErrNoElement = newSyntaxError("an alternative must have at least one element")
+)