MCPcopy
hub / github.com/valyala/quicktemplate / parseFunc

Method parseFunc

parser/parser.go:168–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166}
167
168func (p *parser) parseFunc() error {
169 s := p.s
170 t, err := expectTagContents(s)
171 if err != nil {
172 return err
173 }
174 funcStr := "func " + string(t.Value)
175 f, err := parseFuncDef(t.Value)
176 if err != nil {
177 return fmt.Errorf("error in %q at %s: %s", funcStr, s.Context(), err)
178 }
179 p.emitFuncStart(f)
180 for s.Next() {
181 t := s.Token()
182 switch t.ID {
183 case text:
184 p.emitText(t.Value)
185 case tagName:
186 ok, err := p.tryParseCommonTags(t.Value)
187 if err != nil {
188 return fmt.Errorf("error in %q: %s", funcStr, err)
189 }
190 if ok {
191 continue
192 }
193 switch string(t.Value) {
194 case "endfunc":
195 if err = skipTagContents(s); err != nil {
196 return err
197 }
198 p.emitFuncEnd(f)
199 return nil
200 default:
201 return fmt.Errorf("unexpected tag found in %q: %q at %s", funcStr, t.Value, s.Context())
202 }
203 default:
204 return fmt.Errorf("unexpected token found when parsing %q: %s at %s", funcStr, t, s.Context())
205 }
206 }
207 if err := s.LastError(); err != nil {
208 return fmt.Errorf("cannot parse %q: %s", funcStr, err)
209 }
210 return fmt.Errorf("cannot find endfunc tag for %q at %s", funcStr, s.Context())
211}
212
213func (p *parser) parseFor() error {
214 s := p.s

Callers 1

parseTemplateMethod · 0.95

Calls 11

emitFuncStartMethod · 0.95
emitTextMethod · 0.95
tryParseCommonTagsMethod · 0.95
emitFuncEndMethod · 0.95
expectTagContentsFunction · 0.85
parseFuncDefFunction · 0.85
skipTagContentsFunction · 0.85
ContextMethod · 0.80
NextMethod · 0.80
TokenMethod · 0.80
LastErrorMethod · 0.80

Tested by

no test coverage detected