| 14 | } |
| 15 | |
| 16 | func (*CodeParser) Match(tokens []*tokenizer.Token) (int, bool) { |
| 17 | if len(tokens) < 3 { |
| 18 | return 0, false |
| 19 | } |
| 20 | if tokens[0].Type != tokenizer.Backtick { |
| 21 | return 0, false |
| 22 | } |
| 23 | |
| 24 | contentTokens, matched := []*tokenizer.Token{}, false |
| 25 | for _, token := range tokens[1:] { |
| 26 | if token.Type == tokenizer.Newline { |
| 27 | return 0, false |
| 28 | } |
| 29 | if token.Type == tokenizer.Backtick { |
| 30 | matched = true |
| 31 | break |
| 32 | } |
| 33 | contentTokens = append(contentTokens, token) |
| 34 | } |
| 35 | if !matched || len(contentTokens) == 0 { |
| 36 | return 0, false |
| 37 | } |
| 38 | return len(contentTokens) + 2, true |
| 39 | } |
| 40 | |
| 41 | func (p *CodeParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) { |
| 42 | size, ok := p.Match(tokens) |