Improve Rule classes to be able add a rich context.history in Rules #457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Although norminette only does lexical analysis, we are not able to do syntax analysis that does not force a stop in norminette, we can use is_preprocessor_statement.py as a good example of this, we raise a lot of
CParsingError
when something is not syntactically correct instead of marking the pre-processor statement as "bad" or "malformed" and creating an error withnew_error
to report this error.To add "rich" information in
context.history
I store instances ofRule
s instead of their names inside it. If inIsComment
primary rule we store theCOMMENT
andMULT_COMMENT
tokens in their instance, we can get the 42 header source with something like this:Storing the comments tokens in history, we are able to say if the header is or not in top of file, if header is missing or if is header invalid in an easier way.
Some rules need to be run only once, like
CheckHeader
,CheckLineCount
,CheckLineLen
,CheckSpacing
, etc. and to its case, I added a way to be able run aCheck
rule before and afterRegistry.run_rules
. An example ofCheckLineLen
now:This PR is just a step to improve norminette to be able fix errors like in #394 and #419. I want to make others improves like add more information in
Token
class to be able show better error messages in unexpected exceptions (reported in #411), improvecontext.tokens
to be able add some helpers likeskip_type_specifier
,skip_expression
, etc. to be easy fix problems like in #441.