Skip to content
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

Merged
merged 2 commits into from
Jul 25, 2023

Conversation

raftedproc
Copy link
Contributor

@raftedproc raftedproc commented Jun 27, 2023

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.

@linear
Copy link

linear bot commented Jun 27, 2023

@raftedproc raftedproc changed the title Feat/vm 293 canon stream syntax feat(air-parser) canon stream syntax Jun 28, 2023
@raftedproc raftedproc force-pushed the feat/VM-293-canon-stream-syntax branch from aaa3a5e to 4489ad1 Compare June 28, 2023 11:58
@raftedproc raftedproc changed the title feat(air-parser) canon stream syntax feat(air-parser): canon stream syntax Jul 3, 2023
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));
Copy link
Contributor Author

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.

Copy link
Member

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,
Copy link
Member

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it seems obsolete

@raftedproc raftedproc requested a review from monoid July 4, 2023 11:01
@raftedproc raftedproc added P-low priority: low A-air-parser area: air-parser labels Jul 4, 2023
@raftedproc raftedproc force-pushed the feat/VM-293-canon-stream-syntax branch from 4489ad1 to 90d6f79 Compare July 4, 2023 18:19
@raftedproc raftedproc marked this pull request as ready for review July 5, 2023 09:06
@raftedproc raftedproc force-pushed the feat/VM-293-canon-stream-syntax branch from 90d6f79 to 681ccbd Compare July 10, 2023 17:52
@monoid
Copy link
Contributor

monoid commented Jul 11, 2023

What is the intended syntax change? Please, fill the description.

'%' => Self::StreamMap,
_ => Self::None,
}
}

fn update_type(&self, tag: char) -> Self {
Copy link
Contributor

@monoid monoid Jul 18, 2023

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@raftedproc raftedproc Jul 18, 2023

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.

Copy link
Contributor

@monoid monoid Jul 18, 2023

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@monoid monoid Jul 19, 2023

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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> {
Copy link
Contributor

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify, please?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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));
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@mikevoronov mikevoronov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@github-actions github-actions bot added the e2e Run e2e workflow label Jul 24, 2023
@raftedproc raftedproc force-pushed the feat/VM-293-canon-stream-syntax branch from babb1dd to e40b8bc Compare July 24, 2023 18:17
@raftedproc raftedproc added e2e Run e2e workflow and removed e2e Run e2e workflow labels Jul 24, 2023
@mikevoronov mikevoronov merged commit 8871465 into master Jul 25, 2023
19 of 20 checks passed
@mikevoronov mikevoronov deleted the feat/VM-293-canon-stream-syntax branch July 25, 2023 09:38
@fluencebot fluencebot mentioned this pull request Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-air-parser area: air-parser e2e Run e2e workflow P-low priority: low
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants