Skip to content

Commit

Permalink
Merge pull request #778 from ossf/fix_preprocessor_doc
Browse files Browse the repository at this point in the history
Fix preprocessor documentation
  • Loading branch information
david-a-wheeler authored Feb 4, 2025
2 parents 50b2c46 + 6df883b commit 970d331
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions docs/labs/create_checker.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,33 +619,36 @@ requested, and the second is post-processed pattern that should result.
There's no need for a "failure" test suite here, because we
demand exact results for every test case.

Here is an example (expressed in YAML format):

~~~~yaml
preprocessing:
-
- |-
[\n\r]+
- ""
-
- |-
[ \t]+\\s\+[ \t]+
- "\\s+"
-
- |-
(\\s\*)?[ \t]+(\\s\*)?
- "\\s*"
preprocessingTests:
-
- |-
\s* console \. log \( (["'`])Hello,\x20world!\1 \) ; \s*
- |-
\s*console\s*\.\s*log\s*\(\s*(["'`])Hello,\x20world!\1\s*\)\s*;\s*
-
- |-
\s* foo \s+ bar \\string\\ \s*
- |-
\s*foo\s+bar\s*\\string\\\s*
Here is an example:

~~~~javascript
preprocessing: [
[
// Ignore newlines
String.raw`[\n\r]+`,
""
],
[
// Convert \s+ surrounded by tabs/spaces as \s+ (optimization)
String.raw`[ \t]+\\s\+[ \t]+`,
String.raw`\s+`
],
[
// Convert 1+ spaces/tabs, optionally surrounded by \s*, as \s*
String.raw`(\\s\*)?[ \t]+(\\s\*)?`,
String.raw`\s*`
]
],
preprocessingTests: [
[
String.raw`\s* console \. log \( (["'${BACKQUOTE}])Hello,\x20world!\1 \) ; \s*`,
String.raw`\s*console\s*\.\s*log\s*\(\s*(["'${BACKQUOTE}])Hello,\x20world!\1\s*\)\s*;\s*`
],
[
String.raw`\s* foo \s+ bar \\string\\ \s*`,
String.raw`\s*foo\s+bar\s*\\string\\\s*`
]
]
~~~~

Here is an explanation of each of these preprocessing elements
Expand Down

0 comments on commit 970d331

Please sign in to comment.