diff --git a/README.md b/README.md index 4f79870..aa82e08 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # dt-sql-parser-semantic-analyse-plugin -A [dt-sql-parser](https://github.com/DTStack/dt-sql-parser) plugin with semantic result. [Theory](https://github.com/Kijin-Seija/dt-sql-parser-analyse-demo). +A [dt-sql-parser](https://github.com/DTStack/dt-sql-parser) plugin with semantic result. [Theory(zh-CN)](https://github.com/Kijin-Seija/dt-sql-parser-analyse-demo). ## Installation @@ -29,6 +29,10 @@ import { PostgreSQLParser } from 'dt-sql-parser/dist/lib/pgsql/PostgreSQLParser' const myPlugin = new DtSqlParserSemAnalysePlugin({ parse: { parser: new PostgresSQL() + alias: { + selectstmt: 'selectStatement', + target_el: 'target_label' + } stmts: [ 'selectstmt' ], @@ -51,6 +55,32 @@ console.log(result) **Notice: A rule must start with a/an statement/entity and stop with an entity. You should add a node keywords(keyword is in your parser with format: `RULE_[keyword]`) into stmts/entities before using it.** +## Rule Chain Opeator + +You can set a negative number whose abs equals to a ruleIndex. That means exclude this rule. + +Example: + +```typescript +select_target_alias: [ + PostgreSqlParser.RULE_target_el, + -PostgreSqlParser.RULE_attr_name, + PostgreSqlParser.RULE_collabel +] +``` + +🚧 I will later work on `Operator.AND` and `Operator.OR`. + +## Alias + +Some node names in dt-sql-parser code are different from its antlr4's definition. + +You can find possible alias in https://github.com/DTStack/dt-sql-parser/blob/main/src/grammar/postgresql/PostgreSqlParser.g4, then add it into `alias` option. + +Example: +![alt text](./assets/alias-example.png) + + ## Add a preprocessor ```typescript diff --git a/assets/alias-example.png b/assets/alias-example.png new file mode 100644 index 0000000..9163f2a Binary files /dev/null and b/assets/alias-example.png differ