generic_engine
- Value
spacegreporaliengrep- Default
spacegrep- See also
languages,generic_multiline
A rule with languages: [generic] matches plain text, with one of two engines. spacegrep, the default, splits text into words and brackets, and an ellipsis ... spans at most 10 line breaks. aliengrep lets ... span any number of lines, and can be configured further.
Each engine reads its own options and ignores those of the other engine:
| Engine | Options |
|---|---|
spacegrep | generic_ellipsis_max_span, generic_comment_style |
aliengrep | generic_multiline, generic_caseless, generic_braces, generic_extra_braces, generic_extra_word_characters |
The option has no effect on rules for other languages.
Examples
A block longer than 10 lines
spacegrep.yaml
rules: - id: block pattern: begin ... end message: a block languages: [generic] severity: INFOaliengrep.yaml
rules: - id: block pattern: begin ... end message: a block languages: [generic] severity: INFO options: generic_engine: aliengrepCommand and result
$ python3 -c "open('long.txt','w').write('begin\n' + 'x\n' * 11 + 'end\n')"
$ opengrep scan --config spacegrep.yaml --json long.txt 2>/dev/null | jq .
{
"version": "X.Y.Z",
"results": [],
"errors": [],
"paths": {
"scanned": [
"long.txt"
]
},
"interfile_languages_used": [],
"skipped_rules": []
}
$ opengrep scan --config aliengrep.yaml --json long.txt 2>/dev/null | jq .
{
"version": "X.Y.Z",
"results": [
{
"check_id": "block",
"path": "long.txt",
"start": {
"line": 1,
"col": 1,
"offset": 0
},
"end": {
"line": 13,
"col": 4,
"offset": 31
},
"extra": {
"metavars": {},
"message": "a block",
"metadata": {},
"severity": "INFO",
"fingerprint": "469c2010195f6b6494ec9b2c2fe48d1d88a70a644a35e637ede0e89e945d466f50cdb9d50a7436f43a10ff7ca084557e577b2d05be707e41f08512c8cb43626c_0",
"lines": "begin\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nend",
"is_ignored": false,
"validation_state": "NO_VALIDATOR",
"engine_kind": "Opengrep"
}
}
],
"errors": [],
"paths": {
"scanned": [
"long.txt"
]
},
"interfile_languages_used": [],
"skipped_rules": []
}The block has 12 line breaks between begin and end: too many for spacegrep, which finds nothing, but not for aliengrep, whose finding runs from line 1 to line 13.
An aliengrep option under spacegrep
caseless.yaml
rules: - id: select-users pattern: SELECT ... FROM users message: query on users languages: [generic] severity: INFO options: generic_caseless: truequery.sql
select * from usersCommand and result
$ opengrep scan -q --config caseless.yaml query.sqlThe rule uses spacegrep, which ignores generic_caseless, so the lower-case query is not found and the command prints nothing.