registerPrefix safely registers a parsing function for a prefix token type in the parser's prefixParseFns map. It takes a token type and a prefix parsing function as arguments, and stores the function in the map under the given token type key.
(tokenType token.Type, fn prefixParseFn)
| 823 | // It takes a token type and a prefix parsing function as arguments, and stores the function in the map |
| 824 | // under the given token type key. |
| 825 | func (p *Parser) registerPrefix(tokenType token.Type, fn prefixParseFn) { |
| 826 | if fn == nil { |
| 827 | p.duplicationError(fmt.Sprintf("registerPrefix: nil function for token type %s", tokenType)) |
| 828 | return |
| 829 | } |
| 830 | |
| 831 | if _, exists := p.prefixParseFns[tokenType]; exists { |
| 832 | p.duplicationError(fmt.Sprintf("registerPrefix: token type %s already registered", tokenType)) |
| 833 | return |
| 834 | } |
| 835 | |
| 836 | p.prefixParseFns[tokenType] = fn |
| 837 | } |
| 838 | |
| 839 | // registerInfix safely registers a parsing function for an infix token type in the parser's infixParseFunc map. |
| 840 | // It takes a token type and an infix parsing function as arguments, and stores the function in the map |
no test coverage detected