(tok *token)
| 813 | } |
| 814 | |
| 815 | func tokenStringToAst(tok *token) (*ast.LiteralString, errors.StaticError) { |
| 816 | var node *ast.LiteralString |
| 817 | var validate bool = true |
| 818 | |
| 819 | switch tok.kind { |
| 820 | case tokenStringSingle: |
| 821 | node = &ast.LiteralString{ |
| 822 | NodeBase: ast.NewNodeBaseLoc(tok.loc, tok.fodder), |
| 823 | Value: tok.data, |
| 824 | Kind: ast.StringSingle, |
| 825 | } |
| 826 | case tokenStringDouble: |
| 827 | node = &ast.LiteralString{ |
| 828 | NodeBase: ast.NewNodeBaseLoc(tok.loc, tok.fodder), |
| 829 | Value: tok.data, |
| 830 | Kind: ast.StringDouble, |
| 831 | } |
| 832 | case tokenStringBlock: |
| 833 | node = &ast.LiteralString{ |
| 834 | NodeBase: ast.NewNodeBaseLoc(tok.loc, tok.fodder), |
| 835 | Value: tok.data, |
| 836 | Kind: ast.StringBlock, |
| 837 | BlockIndent: tok.stringBlockIndent, |
| 838 | BlockTermIndent: tok.stringBlockTermIndent, |
| 839 | } |
| 840 | validate = false |
| 841 | case tokenVerbatimStringDouble: |
| 842 | node = &ast.LiteralString{ |
| 843 | NodeBase: ast.NewNodeBaseLoc(tok.loc, tok.fodder), |
| 844 | Value: tok.data, |
| 845 | Kind: ast.VerbatimStringDouble, |
| 846 | } |
| 847 | validate = false |
| 848 | case tokenVerbatimStringSingle: |
| 849 | node = &ast.LiteralString{ |
| 850 | NodeBase: ast.NewNodeBaseLoc(tok.loc, tok.fodder), |
| 851 | Value: tok.data, |
| 852 | Kind: ast.VerbatimStringSingle, |
| 853 | } |
| 854 | validate = false |
| 855 | default: |
| 856 | panic(fmt.Sprintf("Not a string token %#+v", tok)) |
| 857 | } |
| 858 | |
| 859 | if validate { |
| 860 | _, err := StringUnescape((*node).Loc(), (*node).Value) |
| 861 | if err != nil { |
| 862 | return node, errors.MakeStaticError(err.Error(), tok.loc) |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | return node, nil |
| 867 | } |
| 868 | |
| 869 | func (p *parser) parseTerminal() (ast.Node, errors.StaticError) { |
| 870 | tok := p.pop() |
no test coverage detected
searching dependent graphs…