Skip to content

Commit

Permalink
fix(pilota-thrift-parser): compatible with separators after syntax it…
Browse files Browse the repository at this point in the history
…em blocks in idl (#284)

* fix(pilota-thrift-parser): compatible with separators after different item blocks in idl

* chore: add separator compatibility test for idl parser

---------

Co-authored-by: Pure White <[email protected]>
  • Loading branch information
Ggiggle and PureWhiteWu authored Nov 5, 2024
1 parent 376d69d commit 16ad613
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pilota-thrift-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pilota-thrift-parser"
version = "0.11.3"
version = "0.11.4"
edition = "2021"
description = "Pilota thrift Parser."
documentation = "https://docs.rs/pilota"
Expand Down
3 changes: 1 addition & 2 deletions pilota-thrift-parser/src/parser/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ impl Parser for EnumValue {
opt(blank),
opt(Annotations::parse),
opt(list_separator),
opt(blank),
)),
|(name, _, value, _, annotations, _, _)| EnumValue {
|(name, _, value, _, annotations, _)| EnumValue {
name,
value,
annotations: annotations.unwrap_or_default(),
Expand Down
3 changes: 2 additions & 1 deletion pilota-thrift-parser/src/parser/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ impl Parser for Service {
tag("}"),
opt(blank),
opt(Annotations::parse),
opt(list_separator),
)),
|(_, _, name, extends, _, _, functions, _, _, _, annotations)| Service {
|(_, _, name, extends, _, _, functions, _, _, _, annotations, _)| Service {
name,
extends,
functions,
Expand Down
3 changes: 2 additions & 1 deletion pilota-thrift-parser/src/parser/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ impl Parser for StructLike {
tag("}"),
opt(blank),
opt(Annotations::parse),
opt(list_separator),
)),
|(name, _, _, fields, _, _, _, annotations)| StructLike {
|(name, _, _, fields, _, _, _, annotations, _)| StructLike {
name,
fields,
annotations: annotations.unwrap_or_default(),
Expand Down
27 changes: 27 additions & 0 deletions pilota-thrift-parser/src/parser/thrift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,31 @@ mod tests {
"#;
let (_remain, _res) = File::parse(body).unwrap();
}

#[test]
fn test_separator() {
let body = r#"typedef i32 MyInt32
typedef string MyString;
struct TypedefTestStruct {
1: MyInt32 field_MyInt32;
2: MyString field_MyString;
3: i32 field_Int32;
4: string field_String;
};
typedef TypedefTestStruct MyStruct,
const list<string> TEST_LIST = [
"hello",
"world",
];
service Service {
MyStruct testEpisode(1:MyStruct arg)
},"#;
let (remain, res) = File::parse(body).unwrap();
assert!(remain.is_empty());
assert_eq!(res.items.len(), 6);
}
}
3 changes: 2 additions & 1 deletion pilota-thrift-parser/src/parser/typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ impl Parser for Typedef {
Ident::parse,
opt(blank),
opt(Annotations::parse),
opt(list_separator),
)),
|(_, _, r#type, _, alias, _, annotations)| Typedef {
|(_, _, r#type, _, alias, _, annotations, _)| Typedef {
r#type,
alias,
annotations: annotations.unwrap_or_default(),
Expand Down

0 comments on commit 16ad613

Please sign in to comment.