Browse Source

Merge branch 'chsasank-sasank/docs-2'

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
Erez Sh 4 years ago
parent
commit
7538ea4423
1 changed files with 20 additions and 17 deletions
  1. +20
    -17
      docs/classes.rst

+ 20
- 17
docs/classes.rst View File

@@ -7,29 +7,32 @@ Lark
.. autoclass:: lark.Lark
:members: open, parse, save, load

**Using Unicode character classes with regex**

Python's builtin `re` module has a few persistent known bugs and also won't parse
Using Unicode character classes with ``regex``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Python's builtin ``re`` module has a few persistent known bugs and also won't parse
advanced regex features such as character classes.
With `pip install lark-parser[regex]`, the `regex` module will be installed alongside `lark` and can act as a drop-in replacement to `re`.
With ``pip install lark-parser[regex]``, the ``regex`` module will be
installed alongside lark and can act as a drop-in replacement to ``re``.

Any instance of Lark instantiated with ``regex=True`` will use the ``regex`` module instead of ``re``.

Any instance of `Lark` instantiated with `regex=True` will now use the `regex` module instead of `re`.
For example, we can use character classes to match PEP-3131 compliant Python identifiers:

For example, we can now use character classes to match PEP-3131 compliant Python identifiers.
::

Example:
::
from lark import Lark
>>> g = Lark(r"""
?start: NAME
NAME: ID_START ID_CONTINUE*
ID_START: /[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_]+/
ID_CONTINUE: ID_START | /[\p{Mn}\p{Mc}\p{Nd}\p{Pc}·]+/
""", regex=True)

from lark import Lark
>>> g = Lark(r"""
?start: NAME
NAME: ID_START ID_CONTINUE*
ID_START: /[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_]+/
ID_CONTINUE: ID_START | /[\p{Mn}\p{Mc}\p{Nd}\p{Pc}·]+/
""", regex=True)
>>> g.parse('வணக்கம்')
'வணக்கம்'

>>> g.parse('வணக்கம்')
'வணக்கம்'

Tree
----
@@ -44,7 +47,7 @@ Token
.. autoclass:: lark.Token

Transformer, Visitor & Interpreter
---------------------------------
----------------------------------

See :doc:`visitors`.



Loading…
Cancel
Save