From f16811613aeb79444a3555115e4031f68cd183b9 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Mon, 14 Jun 2021 23:22:02 +0900 Subject: Add spec parser Currently, the parser only supports definitions of lexical specification. --- spec/syntax_error.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/syntax_error.go (limited to 'spec/syntax_error.go') 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") +) -- cgit v1.2.3