(classNode *ClassNode)
| 298 | } |
| 299 | |
| 300 | func (p *Parser) parseClassBody(classNode *ClassNode) { |
| 301 | braceCount := 1 |
| 302 | _ = p.pos // Was startPos |
| 303 | |
| 304 | for p.pos < len(p.tokens) { |
| 305 | t := p.peek() |
| 306 | |
| 307 | if t.Value == "}" { |
| 308 | braceCount-- |
| 309 | p.next() |
| 310 | if braceCount == 0 { |
| 311 | classNode.EndLine = t.Line |
| 312 | break |
| 313 | } |
| 314 | continue |
| 315 | } else if t.Value == "{" { |
| 316 | braceCount++ |
| 317 | p.next() |
| 318 | continue |
| 319 | } |
| 320 | |
| 321 | // Try to identify methods |
| 322 | // Heuristic: Type Name ( Args ) { |
| 323 | // Or: public Type Name ( Args ) { |
| 324 | // We look ahead |
| 325 | if p.isMethodStart() { |
| 326 | method := p.parseMethod() |
| 327 | if method != nil { |
| 328 | classNode.Methods = append(classNode.Methods, method) |
| 329 | continue // parseMethod consumes the body |
| 330 | } |
| 331 | } else if p.isFieldStart() { |
| 332 | field := p.parseField() |
| 333 | if field != nil { |
| 334 | classNode.Fields = append(classNode.Fields, field) |
| 335 | } |
| 336 | } else { |
| 337 | p.next() |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | func (p *Parser) isMethodStart() bool { |
| 343 | // Look ahead for ( ... ) { |
no test coverage detected