Markdown code blocks part 5 (#20236)

No logic was added, just a few more `*.md` files have been migrated.
This commit is contained in:
Andrey Makarov 2022-08-17 22:20:22 +03:00 • committed by GitHub
commit 1c31de361d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 486 additions and 413 deletions

View file

@ -175,8 +175,9 @@ The PEG parser implements this grammar (written in PEG syntax)::
expression, identifiers are not interpreted as non-terminals, but are
interpreted as verbatim string:
.. code-block:: nim
```nim
abc =~ peg"abc" # is true
```
So it is not necessary to write ``peg" 'abc' "`` in the above example.
@ -186,22 +187,25 @@ Examples
Check if `s` matches Nim's "while" keyword:
.. code-block:: nim
```nim
s =~ peg" y'while'"
```
Exchange (key, val)-pairs:
.. code-block:: nim
```nim
"key: val; key2: val2".replacef(peg"{\ident} \s* ':' \s* {\ident}", "$2: $1")
```
Determine the ``#include``'ed files of a C file:
.. code-block:: nim
```nim
for line in lines("myfile.c"):
if line =~ peg"""s <- ws '#include' ws '"' {[^"]+} '"' ws
comment <- '/*' @ '*/' / '//' .*
ws <- (comment / \s+)* """:
echo matches[0]
```
PEG vs regular expression
-------------------------