-
Notifications
You must be signed in to change notification settings - Fork 18
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
Custom grammar #36
Comments
Applied in 6a125d3 |
Hi, I am wondering, what are the advantages of using pyparsing vs using regex in the decorator, as in the below example: https://behave.readthedocs.io/en/stable/api.html#step-parameters The first thing that comes to my mind is that regex gets unreadable really quickly. With pyparsing this is perhaps less of an issue. |
I think you can reach the same with using regex as well, but pyparsing seems way more readable like you mention. There are some additional advantages that are probably/possibly also doable with regular expressions, but I found them quite intuitive with pyparsing. e.g., it's possible to modify a parsed value immediately. For instance, the following line of code converts a string to an integer: It is also possible to group/nest statements. For example, in the following two sentences:
Can be parsed with
Then Each "IfcAlignment" must be nested by exactly 1 instance(s) of "IfcAlignmentHorizontal"
The same for There is also another example for the relationship_type (e.g. is nested by, nests, assigning, etc ..) in this PR #48. More specifically, in ifc-gherkin-rules/features/steps/steps.py Lines 643 to 646 in f4e5bc9
Pyparsing also has support for nested statements like this by using recursion. I feel this would be a bit more robust and readable as there will be less 'Optional' statements/ and less dependency on order. But yeah, I am still trying that out/experimenting with it. Something like :
|
When considering the parsing of IFC versions and MVDs, is it possible to achieve this without using the " symbols, in order to maintain consistency? ifc-gherkin-rules/features/SPS001_Basic-spatial-structure-for-buildings.feature Lines 15 to 16 in 05329ef
|
@aothms @Ghesselink is this still valid or obsolete? |
As an addition to the default behave grammar parsing. For example, to specify which values to permit
Given all instances of IfcGeometricRepresentationContext[without subtypes
]A solution would then be to use pyparsing
Advantages
The issue is also to link relevant code snippets/PR comments
The text was updated successfully, but these errors were encountered: