From 210a76a5aa0e62f8ab48a94e3c5b5212b5da08fa Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 17 Apr 2021 16:14:58 +0900 Subject: Change the lexical specs of regexp and define concrete syntax error values * Make the lexer treat ']' as an ordinary character in default mode * Define values of the syntax error type that represents error information concretely --- compiler/syntax_error.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 compiler/syntax_error.go (limited to 'compiler/syntax_error.go') diff --git a/compiler/syntax_error.go b/compiler/syntax_error.go new file mode 100644 index 0000000..be2dc38 --- /dev/null +++ b/compiler/syntax_error.go @@ -0,0 +1,37 @@ +package compiler + +import "fmt" + +type SyntaxError struct { + Message string +} + +func newSyntaxError(msg string) *SyntaxError { + return &SyntaxError{ + Message: msg, + } +} + +func (e *SyntaxError) Error() string { + return fmt.Sprintf("syntax error: %s", e.Message) +} + +var ( + // lexical errors + synErrIncompletedEscSeq = newSyntaxError("incompleted escape sequence; unexpected EOF following \\") + synErrInvalidEscSeq = newSyntaxError("invalid escape sequence") + + // syntax errors + synErrUnexpectedToken = newSyntaxError("unexpected token") + synErrNullPattern = newSyntaxError("a pattern must be a non-empty byte sequence") + synErrAltLackOfOperand = newSyntaxError("an alternation expression must have operands") + synErrRepNoTarget = newSyntaxError("a repeat expression must have an operand") + synErrGroupNoElem = newSyntaxError("a grouping expression must include at least one character") + synErrGroupUnclosed = newSyntaxError("unclosed grouping expression") + synErrGroupNoInitiator = newSyntaxError(") needs preceding (") + synErrGroupInvalidForm = newSyntaxError("invalid grouping expression") + synErrBExpNoElem = newSyntaxError("a bracket expression must include at least one character") + synErrBExpUnclosed = newSyntaxError("unclosed bracket expression") + synErrBExpInvalidForm = newSyntaxError("invalid bracket expression") + synErrRangeInvalidOrder = newSyntaxError("a range expression with invalid order") +) -- cgit v1.2.3