Skip to content

Commit 284155e

Browse files
authored
Merge pull request #68 from coreruleset/refactor/comments
refactor: comments
2 parents 21efba4 + 0470fe6 commit 284155e

13 files changed

Lines changed: 6678 additions & 6455 deletions

g4/SecLangLexer.g4

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,13 +1384,16 @@ OPERATOR_QUOTED_STRING
13841384
: (('\\"') | ~([" @!])) (('\\"')|~('"'))* -> pushMode(DEFAULT_MODE)
13851385
;
13861386
1387-
13881387
mode COMMENT_MODE;
13891388
13901389
COMMENT
1391-
: (~[\r\n] | '\\' '\r'? '\n')+
1390+
: (~[\r\n])+
13921391
;
13931392
1394-
NEWLINE_COMMENT
1393+
HASH_COMMENT_BLOCK
13951394
: '\r'? '\n' -> skip,popMode
1395+
;
1396+
1397+
BLOCK_COMMENT_END
1398+
: '\r'? '\n' '\r'? '\n' -> popMode
13961399
;

g4/SecLangParser.g4

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ configuration
2525
;
2626

2727
stmt:
28-
comment* engine_config_rule_directive variables operator actions?
29-
| comment* rule_script_directive file_path actions?
30-
| comment* rule_script_directive QUOTE file_path QUOTE actions?
31-
| comment* remove_rule_by_id remove_rule_by_id_values+
32-
| comment* string_remove_rules string_remove_rules_values
33-
| comment* string_remove_rules QUOTE string_remove_rules_values QUOTE
34-
| comment* update_target_rules update_target_rules_values update_variables
35-
| comment* update_target_rules QUOTE update_target_rules_values QUOTE update_variables
36-
| comment* update_target_rules update_target_rules_values update_variables PIPE new_target
37-
| comment* update_target_rules QUOTE update_target_rules_values QUOTE update_variables PIPE new_target
38-
| comment* update_action_rule id actions
39-
| comment* engine_config_directive
40-
| comment+;
28+
comment_block? engine_config_rule_directive variables operator actions?
29+
| comment_block? rule_script_directive file_path actions?
30+
| comment_block? rule_script_directive QUOTE file_path QUOTE actions?
31+
| comment_block? remove_rule_by_id remove_rule_by_id_values+
32+
| comment_block? string_remove_rules string_remove_rules_values
33+
| comment_block? string_remove_rules QUOTE string_remove_rules_values QUOTE
34+
| comment_block? update_target_rules update_target_rules_values update_variables
35+
| comment_block? update_target_rules QUOTE update_target_rules_values QUOTE update_variables
36+
| comment_block? update_target_rules update_target_rules_values update_variables PIPE new_target
37+
| comment_block? update_target_rules QUOTE update_target_rules_values QUOTE update_variables PIPE new_target
38+
| comment_block? update_action_rule id actions
39+
| comment_block? engine_config_directive
40+
| comment_block+;
41+
42+
comment_block:
43+
comment+ (BLOCK_COMMENT_END | EOF)?
44+
;
4145

4246
comment:
4347
HASH COMMENT?

listener.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
type ParserResult struct {
1616
Comments []string `yaml:"comments"`
17+
CommentsBlocks int `yaml:"comment_blocks"`
1718
Variables []string `yaml:"variables"`
1819
NegatedVarCount int `yaml:"negated_var_count"`
1920
CollectionLengthCount int `yaml:"collection_length_count"`
@@ -197,3 +198,7 @@ func (l *TreeShapeListener) EnterComment(ctx *parser.CommentContext) {
197198
func (l *TreeShapeListener) EnterTransformation_action_value(ctx *parser.Transformation_action_valueContext) {
198199
l.results.DirectiveValues = append(l.results.DirectiveValues, ctx.GetText())
199200
}
201+
202+
func (l *TreeShapeListener) EnterComment_block(ctx *parser.Comment_blockContext) {
203+
l.results.CommentsBlocks++
204+
}

parser/seclang_lexer.go

Lines changed: 2502 additions & 2497 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/seclang_parser.go

Lines changed: 1031 additions & 927 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/seclangparser_base_listener.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/seclangparser_listener.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/seclang_parser/SecLangLexer.py

Lines changed: 2182 additions & 2177 deletions
Large diffs are not rendered by default.

src/seclang_parser/SecLangParser.py

Lines changed: 885 additions & 837 deletions
Large diffs are not rendered by default.

src/seclang_parser/SecLangParserListener.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def exitStmt(self, ctx:SecLangParser.StmtContext):
2626
pass
2727

2828

29+
# Enter a parse tree produced by SecLangParser#comment_block.
30+
def enterComment_block(self, ctx:SecLangParser.Comment_blockContext):
31+
pass
32+
33+
# Exit a parse tree produced by SecLangParser#comment_block.
34+
def exitComment_block(self, ctx:SecLangParser.Comment_blockContext):
35+
pass
36+
37+
2938
# Enter a parse tree produced by SecLangParser#comment.
3039
def enterComment(self, ctx:SecLangParser.CommentContext):
3140
pass

0 commit comments

Comments
 (0)