parseIdentifier parses an identifier.
()
| 98 | |
| 99 | // parseIdentifier parses an identifier. |
| 100 | func (p *parser) parseIdentifier() (result string, err error) { |
| 101 | const prefix = '-' |
| 102 | var numPrefix int |
| 103 | |
| 104 | for len(p.s) > p.i && p.s[p.i] == prefix { |
| 105 | p.i++ |
| 106 | numPrefix++ |
| 107 | } |
| 108 | |
| 109 | if len(p.s) <= p.i { |
| 110 | return "", errors.New("expected identifier, found EOF instead") |
| 111 | } |
| 112 | |
| 113 | if c := p.s[p.i]; !(nameStart(c) || c == '\\') { |
| 114 | return "", fmt.Errorf("expected identifier, found %c instead", c) |
| 115 | } |
| 116 | |
| 117 | result, err = p.parseName() |
| 118 | if numPrefix > 0 && err == nil { |
| 119 | result = strings.Repeat(string(prefix), numPrefix) + result |
| 120 | } |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | // parseName parses a name (which is like an identifier, but doesn't have |
| 125 | // extra restrictions on the first character). |