From 6888c276c10a992c7151126252127082898b69fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20W=C3=B3jtowicz?= Date: Sat, 22 Jun 2019 12:15:09 +0200 Subject: [PATCH] Changed output format to newlines --- README.md | 71 ++++++++++++++++++++++++++++++++++++++------ examples/select.sql | 5 ++-- src/tsql-checker.cpp | 4 +-- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6014905..c93ae70 100644 --- a/README.md +++ b/README.md @@ -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]); ``` @@ -25,19 +26,71 @@ Execution: Output `select.tokens`: ```plaintext -select * From TableName WHERE someField > ALL ( SELECT [val] FROM [AnotherTable] ) ; +select +* +From +TableName +WHERE +someField +> +ALL +( +SELECT +[val] +FROM +[AnotherTable] +) +; + ``` 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 diff --git a/examples/select.sql b/examples/select.sql index 35f8f4f..cc0f30c 100644 --- a/examples/select.sql +++ b/examples/select.sql @@ -1,3 +1,4 @@ -select * -From TableName +select * -- inline comment +From TableName /* multiline + comment */ WHERE someField > ALL (SELECT [val] FROM [AnotherTable]); diff --git a/src/tsql-checker.cpp b/src/tsql-checker.cpp index 1421362..a3f3f86 100644 --- a/src/tsql-checker.cpp +++ b/src/tsql-checker.cpp @@ -48,14 +48,14 @@ void explore_tree(antlr4::tree::ParseTree *ctx) { if (antlr4::tree::TerminalNodeImpl *ptr = dynamic_cast(ctx)) { - t_sw << ctx->getText() + " "; + t_sw << ctx->getText() << std::endl; } if (antlr4::RuleContext *ptr = dynamic_cast(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++)