parseIdentifier parses an identifier.
()
| 75 | |
| 76 | // parseIdentifier parses an identifier. |
| 77 | func (p *parser) parseIdentifier() (result string, err error) { |
| 78 | startingDash := false |
| 79 | if len(p.s) > p.i && p.s[p.i] == '-' { |
| 80 | startingDash = true |
| 81 | p.i++ |
| 82 | } |
| 83 | |
| 84 | if len(p.s) <= p.i { |
| 85 | return "", errors.New("expected identifier, found EOF instead") |
| 86 | } |
| 87 | |
| 88 | if c := p.s[p.i]; !(nameStart(c) || c == '\\') { |
| 89 | return "", fmt.Errorf("expected identifier, found %c instead", c) |
| 90 | } |
| 91 | |
| 92 | result, err = p.parseName() |
| 93 | if startingDash && err == nil { |
| 94 | result = "-" + result |
| 95 | } |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | // parseName parses a name (which is like an identifier, but doesn't have |
| 100 | // extra restrictions on the first character). |