-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse extensions correctly. Allow options more. #242
Conversation
9981195
to
b5b9f11
Compare
}, | ||
)(input) | ||
} | ||
|
||
fn option_ignore(input: &str) -> IResult<&str, ()> { | ||
value((), delimited(tag("option"), take_until(";"), tag(";")))(input) | ||
value((), delimited(pair(tag("option"), many1(br)), take_until(";"), tag(";")))(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this rule to ensure that this parser only matches option ...
and not optional ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
@@ -823,8 +985,10 @@ mod test { | |||
} | |||
} | |||
|
|||
#[test] | |||
fn test_missing_tokens() { | |||
mod missing_tokens { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this from a function to an inner-module... This seems like a much better idea than having functions. This way, there is the organization, without the foot-gun of not calling functions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me! We can also apply this to test_which_names_can_be_qualified()
.
#[derive(Debug, Clone, Default)] | ||
pub struct Extend { | ||
/// The message being extended. | ||
pub name: String, | ||
/// All fields that are being added to the extended message. | ||
pub fields: Vec<Field>, | ||
} | ||
|
||
impl Extend {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this extend struct, which hopefully will be incorporated into the compiler eventually (possibly by me), but we may want to switch to #235 first.
#[derive(Debug, Clone, Default)] | ||
pub struct Extensions { | ||
pub from: i32, | ||
/// Max number is 536,870,911 (2^29 - 1), as defined in the | ||
/// protobuf docs | ||
pub to: i32, | ||
} | ||
|
||
impl Extensions { | ||
/// The max field number that can be used as an extension. | ||
pub fn max() -> i32 { | ||
536870911 | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear this is related, but orthogonal functionality to
extend X { ... }
This is the functionality for
message A {
...
extensions 500 to max
}
message B {
...
extensions 39 to 339
}
Would love some guidance on what is causing the test failures? They seem unrelated to my changes? |
What's erroring outHi! Just took a quick peek at why it's failing, and from what I can tell it's just because the test cases for enum aliases weren't implemented before, and the test cases are hardcoded to assert that they aren't implemented (more precisely, it asserts that Codewise, in must_fail["v3/test_enum_alias_pb.proto"]="enum alias not implemented"
must_fail["v2/test_enum_alias_pb.proto"]="enum alias not implemented" What to doSince
Option 1 makes me think of the |
Oh there are new releases for |
I think Option 2 is the best choice. Currently, the only documentation for missing features I see is #12. Should we add some docs at the crate level about unsupported features? |
b5b9f11
to
94caca7
Compare
Hmm, I think that would make sense -- and then perhaps close #12 with a note that users should now reference the docs instead (to keep a single source of truth). This could be a different PR, I think. For now, I reckon we could just remove the lines in |
the syntax `extend MESSAGENAME { ... }` is now legal, and parses to an `Extend` struct. The struct is not used in the compiler. Also, options are now parsed and ignored in enums and messages. such as: message A { option an_option = "hello, world!"; option (an_option_extension) = false; }
94caca7
to
a92c9f3
Compare
I made the requested change (hopefully to your agreement). Making official docs and dropping #12 seems like a great idea! |
the syntax
extend MESSAGENAME { ... }
is now legal, and parses to anExtend
struct. The struct is not used in the compiler.Also, options are now parsed and ignored in enums and messages.
such as:
This PR only involves the Parser. It does not compile the extend functionality, only allows it to compile.
I kind of went into this codebase blind to add this, so if I am doing something non-kosher, let me know! I tried not to step on any toes, but I couldn't help myself a couple times. If you want me to revert the couple of style changes, I will happily.
Also, can there be a new release? It seems there has not been one in > 1 year?