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

Added readBison() #54

Merged
merged 9 commits into from
May 19, 2023
Merged

Added readBison() #54

merged 9 commits into from
May 19, 2023

Conversation

BenHanson
Copy link
Collaborator

@BenHanson BenHanson commented May 16, 2023

Fixes: #29

@BenHanson BenHanson requested a review from weltling May 16, 2023 19:45
Copy link
Owner

@weltling weltling left a comment

Choose a reason for hiding this comment

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

I don't see any obvious issues in the parsertl code. Could you please check the other comments, though?

Especially the approach with regard to the static vs. object method is IMHO something that should be looked at more closely. I could further tall for static for example, some factory like API could be initiated. For instance there could be another method to return a parser object like Parser::fromBisonFile("/path/to/file").

Thanks

$p = new Parser;

$p->readBison("%%\n;start: 'a';%%\n");
$p->build();
Copy link
Owner

Choose a reason for hiding this comment

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

Would it be expected, that any rules to be possibly added after readBison() call? If not, perhaps API wise it would be cleaner to have a static method that would look like

// Create and return the full object which is already in the finalized state
$p = Parser::fromBison(...);

Even if it should be possible to add more rules after reading the dump, perhaps semantically still it would make sense to have it in the static variant to save the line with the new call?

Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now, it is simply an alternative to calling all the different functions on a rule object.

$lex->push("a", $p->tokenId("'a'"));
$lex->build();

echo $p->validate("a", $lex) . "\n";
Copy link
Owner

Choose a reason for hiding this comment

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

Could you switch to using var_dump instead? It'll show the type of the returned value as well.

Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test now does a dump() instead and the test also supports UTF-32

@@ -0,0 +1,24 @@
--TEST--
readBison() test
Copy link
Owner

Choose a reason for hiding this comment

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

Could we have yet a test where an exception is thrown? Like perhaps feed some random garbage, etc. or something that would certainly fail it?

Thanks

@weltling
Copy link
Owner

Ben, could you please also add like Fixes: #29 to the description, so it creates a link between the issue and the pr. thanks


parsertl::debug::dump(par.rules, ss);
str = ss.str();
php_write((void*)str.c_str(), str.size());
#endif
Copy link
Owner

Choose a reason for hiding this comment

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

This seems to be fixing #27, not related to the readBison feature. Should it be separated into another PR please?

Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fix is necessary in order for the readBison() test to work.

Thanks

Copy link
Owner

Choose a reason for hiding this comment

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

I see. Perhaps it just should have been approached in reverse order - first the dump fix, then the bison fix. Then one could split features by PR. Looks like it'd be best to land both in this PR then, to avoid additional inconvenience. Probably should land this one once both features are finalized then. I'll check to add more tests also once this is in.

Thanks

Copy link
Collaborator Author

@BenHanson BenHanson May 19, 2023

Choose a reason for hiding this comment

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

Can we merge this one now?

Like you said, we can add extras later.

I'd like to address the other issues ASAP now. I'm hoping they will all be quick from now on.

I'd like to address the other std::cout calls next.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, it looks fine now. I think the last small piece is to add the missing header to the package.xml to make all green, then can continue on the fresh state.

Thanks

template<typename T>
void stream_num(const T num_, std::basic_ostream<char32_t>& ss_)
{
std::stringstream css_;
Copy link
Owner

Choose a reason for hiding this comment

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

I guess the build complains about missing sstream include here?

Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the heads up. Fixed now.

@BenHanson BenHanson requested a review from weltling May 19, 2023 16:24
@BenHanson BenHanson merged commit 30c5f56 into weltling:main May 19, 2023
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.

[future request] Parser: Add import method. (load result of dump method).
2 participants