aboutsummaryrefslogtreecommitdiff
path: root/spec/syntax_error.go
blob: b427bedb485928fb0a0821ded6d0fb7c11e0d51f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package spec

type SyntaxError struct {
	message string
}

func newSyntaxError(message string) *SyntaxError {
	return &SyntaxError{
		message: message,
	}
}

func (e *SyntaxError) Error() string {
	return e.message
}

var (
	// lexical errors
	synErrAutoGenID         = newSyntaxError("you cannot define an identifier beginning with an underscore")
	synErrUnclosedTerminal  = newSyntaxError("unclosed terminal")
	synErrInvalidEscSeq     = newSyntaxError("invalid escape sequence")
	synErrIncompletedEscSeq = newSyntaxError("incompleted escape sequence; unexpected EOF following a backslash")
	synErrEmptyPattern      = newSyntaxError("a pattern must include at least one character")
	synErrZeroPos           = newSyntaxError("a position must be greater than or equal to 1")

	// syntax errors
	synErrInvalidToken         = newSyntaxError("invalid token")
	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")
	synErrNoDirectiveName      = newSyntaxError("a directive needs a name")
	synErrProdDirNoNewline     = newSyntaxError("a production directive must be followed by a newline")
	synErrSemicolonNoNewline   = newSyntaxError("a semicolon must be followed by a newline")
	synErrFragmentNoPattern    = newSyntaxError("a fragment needs one pattern element")
	synErrTreeInvalidFirstElem = newSyntaxError("the first element of a tree structure must be an ID")
	synErrTreeUnclosed         = newSyntaxError("unclosed tree structure")
)