Skip to content

Commit 0ba2bca

Browse files
authored
New extract, in rule_syntax_v2.atd (#191)
test plan: see tests in related PR in semgrep - [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.17.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades
1 parent 4ec13c0 commit 0ba2bca

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

rule_schema_v2.atd

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* also the old syntax.
3232
*
3333
* TODO:
34-
* - extract
3534
* - secrets
3635
* - steps (but not join)
3736
* - new metavariable types
@@ -66,35 +65,43 @@ type rule = {
6665
message: string;
6766
severity: severity;
6867

69-
(* TODO: selector vs analyzer *)
68+
(* later: selector vs analyzer of Martin *)
7069
languages: language list;
7170

7271
(* CHECK: exactly one of those fields must be set *)
7372
?match_ <json name="match">: formula option;
7473
?taint: taint option;
75-
?extract: extract option;
76-
(* TODO: steps, secrets *)
77-
(* TODO? product: product; *)
74+
(* TODO: steps:, secrets: *)
7875

79-
(* can work with match/taint/..., maybe not extract *)
76+
(* work with match: (and in theory also with taint: ) *)
8077
?project_depends_on <json name="r2c-internal-project-depends-on">:
8178
project_depends_on option;
79+
(* work with match: (and in theory also with taint: )
80+
*
81+
* alt: message:/severity: could be made optional when extract: is set,
82+
* but it's annoying to change those types just for extract. Moreover,
83+
* users can easily put severity: INFO and a fake message:,
84+
* and at least they can easily test the matching part of the rule
85+
* by removing the extract and run it like a regular rule.
86+
*)
87+
?extract: extract option;
8288

83-
(* alt: later: could be replaced by a pattern-filename: *)
89+
(* alt: later: could be replaced by a 'filename:' in formula *)
8490
?paths: paths option;
8591

8692
?fix: string option;
8793
?fix_regex: fix_regex option;
8894

89-
(* TODO? impose more constraints on metadata? standard fields? *)
90-
?metadata: raw_json option;
95+
(* later: equivalences: ... *)
9196
?options: rule_options option;
9297

93-
?version: version option;
98+
(* TODO? impose more constraints on metadata? standard fields?
99+
* TODO? add also a product: product; ?
100+
*)
101+
?metadata: raw_json option;
102+
94103
?min_version: version option;
95104
?max_version: version option;
96-
97-
(* later: equivalences: ... *)
98105
}
99106

100107
(* Rule_ID.t, "^[a-zA-Z0-9._-]*$" *)
@@ -284,7 +291,7 @@ type formula = {
284291

285292
(* later: we should remove with a better range logic *)
286293
?inside: formula option;
287-
(* NEW: since 1.49 *)
294+
(* NEW: since 1.49. alt: in condition instead as in 'where: - also: ...' *)
288295
?anywhere: formula option;
289296
(* TODO? ?taint: taint *)
290297

@@ -498,11 +505,34 @@ type namespace = [
498505
type semver_range = string
499506

500507
(*****************************************************************************)
501-
(* TODO: Extract mode *)
508+
(* Extract *)
502509
(*****************************************************************************)
503510

504-
type extract = raw_json
511+
type extract = {
512+
metavariable: mvar;
513+
?dest_language <json name="dest-language">: language option;
514+
?dest_rules <json name="dest-rules">: dest_rules option;
515+
(* map-reduce! *)
516+
?reduce: extract_reduce option;
517+
?transform: extract_transform option;
518+
}
519+
520+
type dest_rules = {
521+
(* CHECK: at least one of those options is set *)
522+
?exclude_ <json name="exclude">: rule_id list option;
523+
?include_ <json name="include">: rule_id list option;
524+
}
505525

526+
type extract_reduce = [
527+
| Concat <json name="concat">
528+
| Separate <json name="separate">
529+
]
530+
531+
type extract_transform = [
532+
| NoTransform <json name="no_transform">
533+
| UnquoteString <json name="unquote_string">
534+
| ConcatJsonStringArray <json name="concat_json_string_array">
535+
]
506536
(*****************************************************************************)
507537
(* TODO: Secrets *)
508538
(*****************************************************************************)

0 commit comments

Comments
 (0)