MCPcopy Create free account
hub / github.com/andybalholm/cascadia / parseIdentifier

Method parseIdentifier

parser.go:100–122  ·  view source on GitHub ↗

parseIdentifier parses an identifier.

()

Source from the content-addressed store, hash-verified

98
99// parseIdentifier parses an identifier.
100func (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).

Callers 5

TestParseIdentifierFunction · 0.95
parseTypeSelectorMethod · 0.95
parseClassSelectorMethod · 0.95

Calls 2

parseNameMethod · 0.95
nameStartFunction · 0.85

Tested by 1

TestParseIdentifierFunction · 0.76