-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add optional filename and line number information to patterns #34
Conversation
Thank you for your contribution. I will have a look at the proposed changes. |
I like the idea, but two things are preventing me from merging as is; this adds new functionality, so following semantic versioning this should create version I'm wondering about what the default value for Would it make sense to change the signature to If you can come up with a good use-case for specifying a filename when parsing from a string, then I am also okay with using the signature |
Absolutely, you're right, this adds new backwards compatible public API. Will fix.
I was torn on how to handle As to the use case for $data_from_owners = file_get_contents('OWNERS');
// just an example, the idea is that you often need to do something with the contents of the file you will
// be parsing, but you still want to parse the contents as if they had been read directly from a file.
$digest = hash('sha256', $data_from_owners);
$patterns = Parser::parseString($data_from_owners, 'OWNERS'); The idea is that there are cases where you are ultimately reading from a file but you need to have access to the data that resides in the file prior to parsing it. All of that said, though, this is not a use case I currently have. It is, indeed, speculative. As the maintainer, I'll defer to you if you think the speculative use is worth it. Thank you for the review. I'll update this PR soon. |
1. Increment minor semvar version. 2. Make filename property nullable for SourceInfo. 3. Parser::parseString($filename) includes SourceInfo on patterns but w/ null filename.
Updated. Just let me know if you think the use case for passing |
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.
Let's make the SourceInfo
not nullable. If that's done I'll merge this one.
Thanks for the contribution. I've merged and tagged version 2.3.0. |
We would like to be able to indicate the line number for the relevant pattern in error/warning messages in a project. This pull request adds a nullable
SourceInfo
property toPattern
that may be optionally via the constructor. TheParser
has been updated to always populate that property when parsing viaparseFile
.When using
parseString
, the filename defaults to an empty string (''
) but can be overwritten via the$filename
parameter. Having the parameter optional maintains backwards compatibility but also makes source info available on both parse methods in the parser.