parseFromClause parses the FROM clause of the query.
(q *query.Query)
| 69 | |
| 70 | // parseFromClause parses the FROM clause of the query. |
| 71 | func (p *parser) parseFromClause(q *query.Query) error { |
| 72 | if p.expect(tokenizer.From) == nil { |
| 73 | err := p.currentError() |
| 74 | if p.expect(tokenizer.Identifier) != nil { |
| 75 | // No FROM, but an identifier -> malformed query. |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | // No specified directory, so we default to the CWD. |
| 80 | q.Sources["include"] = append(q.Sources["include"], ".") |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | if err := p.parseSourceList(&q.Sources, &q.SourceAliases); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | // Replace the tilde with the home directory in each source directory. This |
| 89 | // is only required when the query is wrapped in quotes, since the shell |
| 90 | // will automatically expand tildes otherwise. |
| 91 | u, err := user.Current() |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | for _, sourceType := range []string{"include", "exclude"} { |
| 96 | for i, src := range q.Sources[sourceType] { |
| 97 | if strings.Contains(src, "~") { |
| 98 | q.Sources[sourceType][i] = filepath.Join(u.HomeDir, src[1:]) |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return nil |
| 104 | } |
| 105 | |
| 106 | // parseWhereClause parses the WHERE clause of the query. |
| 107 | func (p *parser) parseWhereClause(q *query.Query) error { |