File tree 2 files changed +49
-0
lines changed 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,6 @@ path = "src/lib.rs"
21
21
log = " 0.4.5"
22
22
chrono = " 0.4.6"
23
23
uuid = " 0.7.1"
24
+
25
+ [dev-dependencies ]
26
+ simple_logger = " 1.0.1"
Original file line number Diff line number Diff line change
1
+ extern crate simple_logger;
2
+ extern crate sqlparser;
3
+ ///! A small command-line app to run the parser.
4
+ /// Run with `cargo run --example cli`
5
+ use std:: fs;
6
+
7
+ use sqlparser:: dialect:: GenericSqlDialect ;
8
+ use sqlparser:: sqlparser:: Parser ;
9
+
10
+ fn main ( ) {
11
+ simple_logger:: init ( ) . unwrap ( ) ;
12
+
13
+ let filename = std:: env:: args ( )
14
+ . nth ( 1 )
15
+ . expect ( "No arguments provided!\n \n Usage: cargo run --example cli FILENAME.sql" ) ;
16
+
17
+ let contents =
18
+ fs:: read_to_string ( & filename) . expect ( & format ! ( "Unable to read the file {}" , & filename) ) ;
19
+ let without_bom = if contents. chars ( ) . nth ( 0 ) . unwrap ( ) as u64 != 0xfeff {
20
+ contents. as_str ( )
21
+ } else {
22
+ let mut chars = contents. chars ( ) ;
23
+ chars. next ( ) ;
24
+ chars. as_str ( )
25
+ } ;
26
+ println ! ( "Input:\n '{}'" , & without_bom) ;
27
+ let parse_result = Parser :: parse_sql ( & GenericSqlDialect { } , without_bom. to_owned ( ) ) ;
28
+ match parse_result {
29
+ Ok ( statements) => {
30
+ println ! (
31
+ "Round-trip:\n '{}'" ,
32
+ statements
33
+ . iter( )
34
+ . map( |s| s. to_string( ) )
35
+ . collect:: <Vec <_>>( )
36
+ . join( "\n " )
37
+ ) ;
38
+ println ! ( "Parse results:\n {:#?}" , statements) ;
39
+ std:: process:: exit ( 0 ) ;
40
+ }
41
+ Err ( e) => {
42
+ println ! ( "Error during parsing: {:?}" , e) ;
43
+ std:: process:: exit ( 1 ) ;
44
+ }
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments