@@ -49,7 +49,7 @@ func (r *Rule) UnmarshalJSON(data []byte) error {
4949 }
5050 err = json .Unmarshal (jrule .Action , & jaction )
5151 if err != nil {
52- return fmt .Errorf ("could not unmarshal action %q: %w" , string (jrule .Action ), err )
52+ return fmt .Errorf ("lexer: could not unmarshal action %q: %w" , string (jrule .Action ), err )
5353 }
5454 var action Action
5555 switch jaction .Kind {
@@ -73,7 +73,7 @@ func (r *Rule) UnmarshalJSON(data []byte) error {
7373 action = actual
7474 case "" :
7575 default :
76- return fmt .Errorf ("unknown action %q" , jaction .Kind )
76+ return fmt .Errorf ("lexer: unknown action %q" , jaction .Kind )
7777 }
7878 r .Action = action
7979 return nil
@@ -87,12 +87,12 @@ func (r *Rule) MarshalJSON() ([]byte, error) {
8787 if r .Action != nil {
8888 actionData , err := json .Marshal (r .Action )
8989 if err != nil {
90- return nil , fmt .Errorf ("failed to map action: %w" , err )
90+ return nil , fmt .Errorf ("lexer: failed to map action: %w" , err )
9191 }
9292 jaction := map [string ]interface {}{}
9393 err = json .Unmarshal (actionData , & jaction )
9494 if err != nil {
95- return nil , fmt .Errorf ("failed to map action: %w" , err )
95+ return nil , fmt .Errorf ("lexer: failed to map action: %w" , err )
9696 }
9797 switch r .Action .(type ) {
9898 case nil :
@@ -103,7 +103,7 @@ func (r *Rule) MarshalJSON() ([]byte, error) {
103103 case include :
104104 jaction ["kind" ] = "include"
105105 default :
106- return nil , fmt .Errorf ("unsupported action %T" , r .Action )
106+ return nil , fmt .Errorf ("lexer: unsupported action %T" , r .Action )
107107 }
108108 actionJSON , err := json .Marshal (jaction )
109109 if err != nil {
@@ -183,7 +183,7 @@ func (p ActionPush) applyAction(lexer *StatefulLexer, groups []string) error {
183183
184184func (p ActionPush ) validate (rules Rules ) error {
185185 if _ , ok := rules [p .State ]; ! ok {
186- return fmt .Errorf ("push to unknown state %q" , p .State )
186+ return fmt .Errorf ("lexer: push to unknown state %q" , p .State )
187187 }
188188 return nil
189189}
@@ -207,7 +207,7 @@ func (i include) applyAction(lexer *StatefulLexer, groups []string) error {
207207func (i include ) applyRules (state string , rule int , rules compiledRules ) error {
208208 includedRules , ok := rules [i .State ]
209209 if ! ok {
210- return fmt .Errorf ("invalid include state %q" , i .State )
210+ return fmt .Errorf ("lexer: invalid include state %q" , i .State )
211211 }
212212 clone := make ([]compiledRule , len (includedRules ))
213213 copy (clone , includedRules )
@@ -245,7 +245,7 @@ func New(rules Rules) (*StatefulDefinition, error) {
245245 for i , rule := range set {
246246 if validate , ok := rule .Action .(validatingRule ); ok {
247247 if err := validate .validate (rules ); err != nil {
248- return nil , fmt .Errorf ("invalid action for rule %q: %w" , rule .Name , err )
248+ return nil , fmt .Errorf ("lexer: invalid action for rule %q: %w" , rule .Name , err )
249249 }
250250 }
251251 pattern := "^(?:" + rule .Pattern + ")"
@@ -257,7 +257,7 @@ func New(rules Rules) (*StatefulDefinition, error) {
257257 if match == nil || len (match [1 ])% 2 == 0 {
258258 re , err = regexp .Compile (pattern )
259259 if err != nil {
260- return nil , fmt .Errorf ("%s.%d: %s" , key , i , err )
260+ return nil , fmt .Errorf ("lexer: %s.%d: %s" , key , i , err )
261261 }
262262 }
263263 compiled [key ] = append (compiled [key ], compiledRule {
@@ -272,7 +272,7 @@ restart:
272272 for i , rule := range rules {
273273 if action , ok := rule .Action .(RulesAction ); ok {
274274 if err := action .applyRules (state , i , compiled ); err != nil {
275- return nil , fmt .Errorf ("%s.%d: %s" , state , i , err )
275+ return nil , fmt .Errorf ("lexer: %s.%d: %s" , state , i , err )
276276 }
277277 goto restart
278278 }
@@ -291,7 +291,7 @@ restart:
291291 for _ , key := range keys {
292292 for i , rule := range compiled [key ] {
293293 if dup , ok := duplicates [rule .Name ]; ok && rule .Pattern != dup .Pattern {
294- panic (fmt .Sprintf ("duplicate key %q with different patterns %q != %q" , rule .Name , rule .Pattern , dup .Pattern ))
294+ panic (fmt .Sprintf ("lexer: duplicate key %q with different patterns %q != %q" , rule .Name , rule .Pattern , dup .Pattern ))
295295 }
296296 duplicates [rule .Name ] = rule
297297 compiled [key ][i ] = rule
@@ -382,7 +382,7 @@ next:
382382 }
383383 re , err := l .getPattern (candidate )
384384 if err != nil {
385- return Token {}, errorf (l .pos , "rule %q: %s" , candidate .Name , err )
385+ return Token {}, errorf (l .pos , "lexer: rule %q: %s" , candidate .Name , err )
386386 }
387387 m = re .FindStringSubmatchIndex (l .data )
388388 if m != nil && (match == nil || m [1 ] > match [1 ]) {
@@ -398,7 +398,7 @@ next:
398398 if len (sample ) > 16 {
399399 sample = append (sample [:16 ], []rune ("..." )... )
400400 }
401- return Token {}, errorf (l .pos , "invalid input text %q" , string (sample ))
401+ return Token {}, errorf (l .pos , "lexer: invalid input text %q" , string (sample ))
402402 }
403403
404404 if rule .Action != nil {
@@ -407,10 +407,10 @@ next:
407407 groups = append (groups , l .data [match [i ]:match [i + 1 ]])
408408 }
409409 if err := rule .Action .applyAction (l , groups ); err != nil {
410- return Token {}, errorf (l .pos , "rule %q: %s" , rule .Name , err )
410+ return Token {}, errorf (l .pos , "lexer: rule %q: %s" , rule .Name , err )
411411 }
412412 } else if match [0 ] == match [1 ] {
413- return Token {}, errorf (l .pos , "rule %q did not match any input" , rule .Name )
413+ return Token {}, errorf (l .pos , "lexer: rule %q did not match any input" , rule .Name )
414414 }
415415
416416 span := l .data [match [0 ]:match [1 ]]
0 commit comments