| 1009 | } |
| 1010 | |
| 1011 | func (p *codeParser) parseExplicitExpression() *nodeGoStrExpr { |
| 1012 | // one token past the opening '(' |
| 1013 | result := new(nodeGoStrExpr) |
| 1014 | result.pos.start = p.parser.offset |
| 1015 | start := p.peek().pos |
| 1016 | maxread := start |
| 1017 | lastlit := p.peek().String() |
| 1018 | depth := 1 |
| 1019 | loop: |
| 1020 | for { |
| 1021 | switch p.peek().tok { |
| 1022 | case token.LPAREN: |
| 1023 | depth++ |
| 1024 | case token.RPAREN: |
| 1025 | depth-- |
| 1026 | if depth == 0 { |
| 1027 | break loop |
| 1028 | } |
| 1029 | case token.ILLEGAL: |
| 1030 | p.errorf("illegal Go token %q", p.peek().String()) |
| 1031 | case token.EOF: |
| 1032 | p.errorf("unterminated explicit expression, expected closing ')'") |
| 1033 | } |
| 1034 | maxread = p.peek().pos |
| 1035 | lastlit = p.peek().String() |
| 1036 | p.advance() |
| 1037 | } |
| 1038 | n := (p.file.Offset(maxread) - p.file.Offset(start)) + len(lastlit) |
| 1039 | if p.peek().tok != token.RPAREN { |
| 1040 | panic(fmt.Sprintf("internal error: expected ')', got '%s'", p.peek().String())) |
| 1041 | } |
| 1042 | _ = p.sync() |
| 1043 | result.expr = p.sourceFrom(start)[:n] |
| 1044 | result.pos.end = result.pos.start + n |
| 1045 | if _, err := goparser.ParseExpr(result.expr); err != nil { |
| 1046 | p.errorf("illegal Go expression: %w", err) |
| 1047 | } |
| 1048 | return result |
| 1049 | } |
| 1050 | |
| 1051 | // offset is the current global offset into the original source code of the Pushup file. |
| 1052 | // |