MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / syntaxErrorAt

Method syntaxErrorAt

syntax/parser.go:155–197  ·  view source on GitHub ↗

---------------------------------------------------------------------------- Error handling syntaxErrorAt reports a syntax error at the given position.

(pos Pos, msg string)

Source from the content-addressed store, hash-verified

153
154// syntaxErrorAt reports a syntax error at the given position.
155func (p *parser) syntaxErrorAt(pos Pos, msg string) {
156 if trace {
157 p.print("syntax error: " + msg)
158 }
159
160 if p.tok == _EOF && p.first != nil {
161 return // avoid meaningless follow-up errors
162 }
163
164 // add punctuation etc. as needed to msg
165 switch {
166 case msg == "":
167 // nothing to do
168 case strings.HasPrefix(msg, "in "), strings.HasPrefix(msg, "at "), strings.HasPrefix(msg, "after "):
169 msg = " " + msg
170 case strings.HasPrefix(msg, "expecting "):
171 msg = ", " + msg
172 default:
173 // plain error - we don't care about current token
174 p.errorAt(pos, "syntax error: "+msg)
175 return
176 }
177
178 // determine token string
179 var tok string
180 switch p.tok {
181 case _Name, _Semi:
182 tok = p.lit
183 case _Literal:
184 tok = "literal " + p.lit
185 case _Operator:
186 tok = p.op.String()
187 case _AssignOp:
188 tok = p.op.String() + "="
189 case _IncOp:
190 tok = p.op.String()
191 tok += tok
192 default:
193 tok = tokstring(p.tok)
194 }
195
196 p.errorAt(pos, "syntax error: unexpected "+tok+msg)
197}
198
199// tokstring returns the English word for selected punctuation tokens
200// for more readable error messages. Use tokstring (not tok.String())

Callers 5

syntaxErrorMethod · 0.95
funcTypeMethod · 0.95
paramListMethod · 0.95
labeledStmtOrNilMethod · 0.95
headerMethod · 0.95

Calls 4

printMethod · 0.95
tokstringFunction · 0.85
errorAtMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected