Skip to content

Commit d7df5d5

Browse files
authored
Merge pull request #97 from jasonpanosso/jp/create_conversion
2 parents 9c694d7 + f2103cd commit d7df5d5

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

crates/codegen/src/get_node_properties.rs

+18
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,24 @@ fn custom_handlers(node: &Node) -> TokenStream {
777777
tokens.push(TokenProperty::from(Token::Exists));
778778
}
779779
},
780+
"CreateConversionStmt" => quote! {
781+
tokens.push(TokenProperty::from(Token::Create));
782+
if n.def {
783+
tokens.push(TokenProperty::from(Token::Default));
784+
}
785+
tokens.push(TokenProperty::from(Token::ConversionP));
786+
if n.for_encoding_name.len() > 0 {
787+
tokens.push(TokenProperty::from(Token::For));
788+
}
789+
if n.to_encoding_name.len() > 0 {
790+
tokens.push(TokenProperty::from(Token::To));
791+
}
792+
if n.func_name.len() == 1 {
793+
tokens.push(TokenProperty::from(Token::From));
794+
} else if n.func_name.len() > 1 {
795+
panic!("Encountered multiple defined func_name elements in CreateConversionStmt");
796+
}
797+
},
780798
_ => quote! {},
781799
}
782800
}

crates/parser/src/codegen.rs

+20
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,24 @@ mod tests {
297297
],
298298
)
299299
}
300+
301+
#[test]
302+
fn test_create_conversion() {
303+
test_get_node_properties(
304+
"CREATE DEFAULT CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;",
305+
SyntaxKind::CreateConversionStmt,
306+
vec![
307+
TokenProperty::from(SyntaxKind::Create),
308+
TokenProperty::from(SyntaxKind::Default),
309+
TokenProperty::from(SyntaxKind::ConversionP),
310+
TokenProperty::from(SyntaxKind::For),
311+
TokenProperty::from(SyntaxKind::To),
312+
TokenProperty::from(SyntaxKind::From),
313+
TokenProperty::from("utf8".to_string()),
314+
TokenProperty::from("latin1".to_string()),
315+
TokenProperty::from("myconv".to_string()),
316+
TokenProperty::from("myfunc".to_string()),
317+
],
318+
)
319+
}
300320
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;
2+
CREATE DEFAULT CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: "CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;"
4+
---
5+
Parse {
6+
cst: SourceFile@0..60
7+
CreateConversionStmt@0..60
8+
Create@0..6 "CREATE"
9+
Whitespace@6..7 " "
10+
ConversionP@7..17 "CONVERSION"
11+
Whitespace@17..18 " "
12+
Ident@18..24 "myconv"
13+
Whitespace@24..25 " "
14+
For@25..28 "FOR"
15+
Whitespace@28..29 " "
16+
Sconst@29..35 "'UTF8'"
17+
Whitespace@35..36 " "
18+
To@36..38 "TO"
19+
Whitespace@38..39 " "
20+
Sconst@39..47 "'LATIN1'"
21+
Whitespace@47..48 " "
22+
From@48..52 "FROM"
23+
Whitespace@52..53 " "
24+
Ident@53..59 "myfunc"
25+
Ascii59@59..60 ";"
26+
,
27+
errors: [],
28+
stmts: [
29+
RawStmt {
30+
stmt: CreateConversionStmt(
31+
CreateConversionStmt {
32+
conversion_name: [
33+
Node {
34+
node: Some(
35+
String(
36+
String {
37+
sval: "myconv",
38+
},
39+
),
40+
),
41+
},
42+
],
43+
for_encoding_name: "UTF8",
44+
to_encoding_name: "LATIN1",
45+
func_name: [
46+
Node {
47+
node: Some(
48+
String(
49+
String {
50+
sval: "myfunc",
51+
},
52+
),
53+
),
54+
},
55+
],
56+
def: false,
57+
},
58+
),
59+
range: 0..59,
60+
},
61+
],
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: "CREATE DEFAULT CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;"
4+
---
5+
Parse {
6+
cst: SourceFile@0..68
7+
CreateConversionStmt@0..68
8+
Create@0..6 "CREATE"
9+
Whitespace@6..7 " "
10+
Default@7..14 "DEFAULT"
11+
Whitespace@14..15 " "
12+
ConversionP@15..25 "CONVERSION"
13+
Whitespace@25..26 " "
14+
Ident@26..32 "myconv"
15+
Whitespace@32..33 " "
16+
For@33..36 "FOR"
17+
Whitespace@36..37 " "
18+
Sconst@37..43 "'UTF8'"
19+
Whitespace@43..44 " "
20+
To@44..46 "TO"
21+
Whitespace@46..47 " "
22+
Sconst@47..55 "'LATIN1'"
23+
Whitespace@55..56 " "
24+
From@56..60 "FROM"
25+
Whitespace@60..61 " "
26+
Ident@61..67 "myfunc"
27+
Ascii59@67..68 ";"
28+
,
29+
errors: [],
30+
stmts: [
31+
RawStmt {
32+
stmt: CreateConversionStmt(
33+
CreateConversionStmt {
34+
conversion_name: [
35+
Node {
36+
node: Some(
37+
String(
38+
String {
39+
sval: "myconv",
40+
},
41+
),
42+
),
43+
},
44+
],
45+
for_encoding_name: "UTF8",
46+
to_encoding_name: "LATIN1",
47+
func_name: [
48+
Node {
49+
node: Some(
50+
String(
51+
String {
52+
sval: "myfunc",
53+
},
54+
),
55+
),
56+
},
57+
],
58+
def: true,
59+
},
60+
),
61+
range: 0..67,
62+
},
63+
],
64+
}

0 commit comments

Comments
 (0)