-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(air-parser): canon stream syntax #618
Conversation
aaa3a5e
to
4489ad1
Compare
if self.current_offset() == 0 && stream_tag.is_tag() { | ||
fn try_parse_as_tagged_token(&mut self) -> LexerResult<bool> { | ||
let tag = MetTag::from_tag(self.current_char()); | ||
if self.current_offset() == 0 && tag.is_tag() { | ||
if self.string_to_parse.len() == 1 { | ||
let error_pos = self.pos_in_string_to_parse(); | ||
return Err(LexerError::empty_stream_name(error_pos..error_pos)); |
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 will also change the error name if you @mikevoronov find the change suitable.
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.
yep, it seems obsolete
@@ -45,6 +51,7 @@ struct ParserState { | |||
pub(self) digit_met: bool, | |||
pub(self) flattening_met: bool, | |||
pub(self) met_tag: MetTag, | |||
pub(self) canon_type_tag: CanonTypeTag, |
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.
What about placing it into MetTag
struct?
if self.current_offset() == 0 && stream_tag.is_tag() { | ||
fn try_parse_as_tagged_token(&mut self) -> LexerResult<bool> { | ||
let tag = MetTag::from_tag(self.current_char()); | ||
if self.current_offset() == 0 && tag.is_tag() { | ||
if self.string_to_parse.len() == 1 { | ||
let error_pos = self.pos_in_string_to_parse(); | ||
return Err(LexerError::empty_stream_name(error_pos..error_pos)); |
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.
yep, it seems obsolete
4489ad1
to
90d6f79
Compare
90d6f79
to
681ccbd
Compare
What is the intended syntax change? Please, fill the description. |
'%' => Self::StreamMap, | ||
_ => Self::None, | ||
} | ||
} | ||
|
||
fn update_type(&self, tag: char) -> Self { |
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.
IMHO should be updated_canon_type
. It doesn't update self, BTW.
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.
There might be other types in future this is why this is not a canon type update.
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.
But most likely it will be context-dependent, won't it?
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.
Doesn't look like it. Match + if will do the trick.
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.
Then you will need to update all the call site, as you call it now under if
. Perhaps, it worth moving that check inside the function right now.
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 will rename the function into maybe_change_type and move if into it.
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.
You should save reader's "cycles", not yours.
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.
Generally, a verb in a method's name means it changes state. It's not the case here.
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.
The future programmer will be the reader/editor whose cycles I am saving.
maybe_change_type will return a value thus a reader will see the assignment. Moreover the variable it returns to is named tag thus it is reasonable good to deduce the new tag is returned.
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.
IMHO, a method can update state and return something as well.
Anyway, all this is mental burden. Just invent some clear name to save the reader's "cycles" you so care about.
} | ||
|
||
fn is_canon(&self) -> bool { | ||
matches!(self, Self::Canon) |
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.
If you derive PartialEq
on MetTag
, you may simply write *self == Self::Canon
.
It worth deriving Eq
too, as it OK for this type.
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.
What is a benefit comparing with the current code?
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.
Simple equality seems to be more straightforward.
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 tend to stick to whatever is used now and see no real benefit changing this to equality b/c it is internally the same.
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.
Code style and idioms are not about internal changes at all.
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.
IMHO it is unwise to use Eq here given that is_tag() uses !matches and I am not changing is_tag b/c it is outside the scope of this patch. You suggest to break the style from my point of view.
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.
Using a PR for small style/idiomatic changes is OK, otherwise they will never be changed.
matches!
should be used for types that cannot be compared for some reason ("I haven't defined PartialEq just because" is not the reason). This enum is essentially simple C-style enum.
fn try_parse_as_stream_start(&mut self) -> LexerResult<bool> { | ||
let stream_tag = MetTag::from_tag(self.current_char()); | ||
if self.current_offset() == 0 && stream_tag.is_tag() { | ||
fn try_parse_as_tagged_token(&mut self) -> LexerResult<bool> { |
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.
It worth commenting what is "tagged token".
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.
It does.
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.
Can you clarify, please?
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.
Sure. I am going to add comments on this matter. Not sure yet what is a suitable place for the comment.
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.
Added the comments near MetTag implementation.
if self.current_offset() == 1 && tag.is_canon_stream() { | ||
if self.string_to_parse.len() == 2 && tag.is_tag() { | ||
let error_pos = self.pos_in_string_to_parse(); | ||
return Err(LexerError::empty_canon_name(error_pos..error_pos)); |
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 think that it could be expressed in a bit different way, please don't merge the PR, I'll take a look later
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 am going to rename try_parse_as_tagged_token to try_parse_as_stream as was discussed.
681ccbd
to
babb1dd
Compare
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.
utACK
babb1dd
to
e40b8bc
Compare
Maps proposal adds a new way to access canon streams and maps using # sign prefix, e.g. #$canon_stream, #%canon_map. This patch adds support for # prefix accessing canon structures.