Markdown code blocks part 5 (#20236)
No logic was added, just a few more `*.md` files have been migrated.
This commit is contained in:
parent
60f6724b70
commit
1c31de361d
21 changed files with 486 additions and 413 deletions
|
|
@ -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
|
||||
-------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue