registerInfix safely registers a parsing function for an infix token type in the parser's infixParseFunc map. It takes a token type and an infix parsing function as arguments, and stores the function in the map under the given token type key.
(tokenType token.Type, fn infixParseFn)
| 840 | // It takes a token type and an infix parsing function as arguments, and stores the function in the map |
| 841 | // under the given token type key. |
| 842 | func (p *Parser) registerInfix(tokenType token.Type, fn infixParseFn) { |
| 843 | if fn == nil { |
| 844 | p.duplicationError(fmt.Sprintf("registerInfix: nil function for token type %s", tokenType)) |
| 845 | return |
| 846 | } |
| 847 | |
| 848 | if _, exists := p.infixParseFunc[tokenType]; exists { |
| 849 | p.duplicationError(fmt.Sprintf("registerInfix: token type %s already registered", tokenType)) |
| 850 | return |
| 851 | } |
| 852 | |
| 853 | p.infixParseFunc[tokenType] = fn |
| 854 | } |
| 855 | |
| 856 | // duplicationError adds an error message to the parser's error list indicating that a duplication was found. |
| 857 | // It takes a key string as an argument that is used to identify the source of the duplication in the input. |
no test coverage detected