Skip to content

Commit

Permalink
Changed output format to newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-wojtowicz committed Jun 22, 2019
1 parent 196492d commit 6888c27
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
71 changes: 62 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Windows and Linux binaries can be downloaded from [releases](https://github.com/
Input `select.sql`:

```sql
select *
From TableName
select * -- inline comment
From TableName /* multiline
comment */
WHERE someField > ALL (SELECT [val] FROM [AnotherTable]);
```

Expand All @@ -25,19 +26,71 @@ Execution:
Output `select.tokens`:

```plaintext
select * From TableName WHERE someField > ALL ( SELECT [val] FROM [AnotherTable] ) ; <EOF>
select
*
From
TableName
WHERE
someField
>
ALL
(
SELECT
[val]
FROM
[AnotherTable]
)
;
<EOF>
```


Output `select.grammar`:

```plaintext
tsql_file batch sql_clauses sql_clause dml_clause select_statement query_expression query_specification
select_list select_list_elem asterisk table_sources table_source table_source_item_joined table_source_item
table_name_with_hint table_name id simple_id search_condition search_condition_and search_condition_not
predicate expression full_column_name id simple_id comparison_operator subquery select_statement
query_expression query_specification select_list select_list_elem column_elem id table_sources table_source
table_source_item_joined table_source_item table_name_with_hint table_name id
tsql_file
batch
sql_clauses
sql_clause
dml_clause
select_statement
query_expression
query_specification
select_list
select_list_elem
asterisk
table_sources
table_source
table_source_item_joined
table_source_item
table_name_with_hint
table_name
id
simple_id
search_condition
search_condition_and
search_condition_not
predicate
expression
full_column_name
id
simple_id
comparison_operator
subquery
select_statement
query_expression
query_specification
select_list
select_list_elem
column_elem
id
table_sources
table_source
table_source_item_joined
table_source_item
table_name_with_hint
table_name
id
```

## Notes
Expand Down
5 changes: 3 additions & 2 deletions examples/select.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
select *
From TableName
select * -- inline comment
From TableName /* multiline
comment */
WHERE someField > ALL (SELECT [val] FROM [AnotherTable]);
4 changes: 2 additions & 2 deletions src/tsql-checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ void explore_tree(antlr4::tree::ParseTree *ctx)
{
if (antlr4::tree::TerminalNodeImpl *ptr = dynamic_cast<antlr4::tree::TerminalNodeImpl*>(ctx))
{
t_sw << ctx->getText() + " ";
t_sw << ctx->getText() << std::endl;
}

if (antlr4::RuleContext *ptr = dynamic_cast<antlr4::RuleContext*>(ctx))
{
std::string rule_name = rule_names[ptr->getRuleIndex()];

g_sw << rule_name + " ";
g_sw << rule_name << std::endl;
}

for (int i = 0; i < ctx->children.size(); i++)
Expand Down

0 comments on commit 6888c27

Please sign in to comment.