Skip to content

Conversation

@louga31
Copy link

@louga31 louga31 commented Sep 18, 2023

This pull request add support for alphanumeric labels.
I have added tests to it.

Currently, it only works with labels without numbers, I'm new to the Moo library and I couldn't get it to match my string "type", it always match number or id (if I put string above them it breaks everything).
If this parsing issue is fixed, the rest of the code should support label names with numbers.

@louga31 louga31 changed the title Add support for named labels Add support for alphanumeric labels Sep 18, 2023
Copy link
Owner

@aebabis aebabis left a comment

Choose a reason for hiding this comment

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

Thanks for expressing interest in improving this project. I agree this is a good feature to add, but the new forEach loops are verbose, and I think we should try to eliminate them before merging, if possible

@aebabis
Copy link
Owner

aebabis commented Oct 6, 2023

Sorry. I didn't notice your PR comment, only your commit messages; now I understand you're aware there are bugs.

I don't know if I'll have the time to locate and fix the bug, but if you can add a 3rd test that should pass but fails, I'll at least take a stab at it.

@louga31
Copy link
Author

louga31 commented Oct 6, 2023

Sorry. I didn't notice your PR comment, only your commit messages; now I understand you're aware there are bugs.

I don't know if I'll have the time to locate and fix the bug, but if you can add a 3rd test that should pass but fails, I'll at least take a stab at it.

I will add tests for this and the mix of named and integer labels

@louga31
Copy link
Author

louga31 commented Oct 6, 2023

The lastest commit fixes the issue, now I need to improve the code and do some cleanup and it should be ready

.filter(({state}) => typeof state === 'number')
.map(({statements}) => statements.map(s => s.start + s.operations.length))
.flat();
return getMaxRounded(ends);
Copy link
Owner

Choose a reason for hiding this comment

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

This all looks really good. One final suggestion:

Suggested change
return getMaxRounded(ends);
return Math.max(0, ...ends) + 1;

I don't think it's necessary to threshold the label to 10 since the user never sees the generated state numbers. Taking it out would remove the need for the helper function.

Unless.... we wanted to make every generated state be thresholded so that IDEs could give the information in tooltips using static code analysis. Would this be a useful feature? Because right now, we're just thresholding the first string-labelled state which doesn't make a lot of sense.

Copy link
Author

Choose a reason for hiding this comment

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

The code was rounding all the generated labels to the next multiple of 10 (10, 20, ...) but yeah, this is not strictly necessary, so I removed it

@aebabis
Copy link
Owner

aebabis commented Nov 1, 2023

@louga31 I pulled this down and tried to fix it. I struggled because I've forgotten how to deal with lexer ambiguities and don't currently have time to relearn. Would you happen to know anyone who can look at grammar.ne?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants