Skip to content

[Macro] Implement the parse_* fn generation macro #909

Closed
@ding-young

Description

Background

Currently, we defined parse_* fn separately, which shows similar pattern; 1) tokenize 2) parse tokens with specific sql-parser fn.
By introducing new decl macro which takes fn_name, parse_fn_name, output type as args, parse_* functions can be easily generated.

pub fn parse_comma_separated_exprs<Sql: AsRef<str>>(sql_exprs: Sql) -> Result<Vec<SqlExpr>> {
let tokens = Tokenizer::new(&DIALECT, sql_exprs.as_ref())
.tokenize()
.map_err(|e| Error::Parser(format!("{:#?}", e)))?;
Parser::new(tokens, &DIALECT)
.parse_comma_separated(Parser::parse_expr)
.map_err(|e| Error::Parser(format!("{:#?}", e)))
}
pub fn parse_select_item<Sql: AsRef<str>>(sql_select_item: Sql) -> Result<SqlSelectItem> {
let tokens = Tokenizer::new(&DIALECT, sql_select_item.as_ref())
.tokenize()
.map_err(|e| Error::Parser(format!("{:#?}", e)))?;
Parser::new(tokens, &DIALECT)
.parse_select_item()
.map_err(|e| Error::Parser(format!("{:#?}", e)))
}

TODO

  1. impl parse_* macro
  2. replace code blocks with macro

Metadata

Assignees

Labels

improvementImprovements for existing features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions