diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-06-14 23:22:02 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-06-15 19:16:58 +0900 |
commit | f16811613aeb79444a3555115e4031f68cd183b9 (patch) | |
tree | 3e4207ddd7f331fdcb11c86e2273bcbe262e9d0f /spec/syntax_error.go | |
parent | Update README (diff) | |
download | cotia-f16811613aeb79444a3555115e4031f68cd183b9.tar.gz cotia-f16811613aeb79444a3555115e4031f68cd183b9.tar.xz |
Add spec parser
Currently, the parser only supports definitions of lexical specification.
Diffstat (limited to 'spec/syntax_error.go')
-rw-r--r-- | spec/syntax_error.go | 32 |
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") +) |