Debian Codegraph @

example/errormsg/errors/errors.go

raw symbols SCIP
1 // Code generated by gocc; DO NOT EDIT.
2
3 package errorsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/
4
5 import (
6 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
7 "strconvscip-go gomod github.com/golang/go/src go1.24 strconv/"
8 "stringsscip-go gomod github.com/golang/go/src go1.24 strings/"
9 "unicodescip-go gomod github.com/golang/go/src go1.24 unicode/"
10
11 "github.com/goccmack/gocc/example/errormsg/tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/"
12 )
13
14 type ErrorSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/ErrorSymbol# interface {
15 }
16
17 type Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error# struct {
18 Errscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Err. error
19 ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken. *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/.Tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#
20 ErrorSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorSymbols. []ErrorSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/ErrorSymbol#
21 ExpectedTokensscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ExpectedTokens. []string
22 StackTopscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#StackTop. int
23 }
24
25 func (e *Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#String().() string {
26 w := new(stringsscip-go gomod github.com/golang/go/src go1.24 strings/.Builderscip-go gomod github.com/golang/go/src go1.24 strings/Builder#)
27 if e.Errscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Err. != nil {
28 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintln().(w, "Error ", e.Errscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Err.)
29 } else {
30 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintln().(w, "Error")
31 }
32 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "Token: type=%d, lit=%s\n", e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Type., e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Litscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Lit.)
33 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "Pos: offset=%d, line=%d, column=%d\n", e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Offset., e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Line., e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Column.)
34 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24 fmt/Fprint().(w, "Expected one of: ")
35 for _, sym := range e.ExpectedTokensscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ExpectedTokens. {
36 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24 fmt/Fprint().(w, string(sym), " ")
37 }
38 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintln().(w, "ErrorSymbol:")
39 for _, sym := range e.ErrorSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorSymbols. {
40 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "%v\n", sym)
41 }
42
43 return w.Stringscip-go gomod github.com/golang/go/src go1.24 strings/Builder#String().()
44 }
45
46 func DescribeExpectedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/DescribeExpected().(tokens []string) string {
47 switch len(tokens) {
48 case 0:
49 return "unexpected additional tokens"
50
51 case 1:
52 return "expected " + tokens[0]
53
54 case 2:
55 return "expected either " + tokens[0] + " or " + tokens[1]
56
57 case 3:
58 // Oxford-comma rules require more than 3 items in a list for the
59 // comma to appear before the 'or'
60 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("expected one of %s, %s or %s", tokens[0], tokens[1], tokens[2])
61
62 default:
63 // Oxford-comma separated alternatives list.
64 tokens = append(tokens[:len(tokens)-1], "or "+tokens[len(tokens)-1])
65 return "expected one of " + stringsscip-go gomod github.com/golang/go/src go1.24 strings/.Joinscip-go gomod github.com/golang/go/src go1.24 strings/Join().(tokens, ", ")
66 }
67 }
68
69 func DescribeTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/DescribeToken().(tok *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/.Tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#) string {
70 switch tok.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Type. {
71 case tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/.INVALIDscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/INVALID.:
72 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("unknown/invalid token %q", tok.Litscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Lit.)
73 case tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/.EOFscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/EOF.:
74 return "end-of-file"
75 default:
76 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("%q", tok.Litscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Lit.)
77 }
78 }
79
80 func (e *Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#) Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Error().() string {
81 // identify the line and column of the error in 'gnu' style so it can be understood
82 // by editors and IDEs; user will need to prefix it with a filename.
83 text := fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("%d:%d: error: ", e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Line., e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Column.)
84
85 // See if the error token can provide us with the filename.
86 switch src := e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken..Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Token#Pos..Contextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Pos#Context..(type) {
87 case tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/.Sourcerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Sourcer#:
88 text = src.Sourcescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/token`/Sourcer#Source.() + ":" + text
89 }
90
91 if e.Errscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Err. != nil {
92 // Custom error specified, e.g. by << nil, errors.New("missing newline") >>
93 text += e.Errscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#Err..Error()
94 } else {
95 tokens := make([]string, len(e.ExpectedTokensscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ExpectedTokens.))
96 for idx, token := range e.ExpectedTokensscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ExpectedTokens. {
97 if !unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.IsLetterscip-go gomod github.com/golang/go/src go1.24 unicode/IsLetter().(rune(token[0])) {
98 token = strconvscip-go gomod github.com/golang/go/src go1.24 strconv/.Quotescip-go gomod github.com/golang/go/src go1.24 strconv/Quote().(token)
99 }
100 tokens[idx] = token
101 }
102 text += DescribeExpectedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/DescribeExpected().(tokens)
103 actual := DescribeTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/DescribeToken().(e.ErrorTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/errormsg/errors`/Error#ErrorToken.)
104 text += fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("; got: %s", actual)
105 }
106
107 return text
108 }