From a5495189d9d7db7fa3277e4e321ce14abc8fb024 Mon Sep 17 00:00:00 2001 From: Sasank Chilamkurthy Date: Mon, 17 Aug 2020 17:38:01 +0530 Subject: [PATCH 1/2] convert part of md to rst --- docs/classes.rst | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/classes.rst b/docs/classes.rst index 59a6f0b..a880a97 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -7,29 +7,33 @@ 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 -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`. +Using Unicode character classes with ``regex`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Any instance of `Lark` instantiated with `regex=True` will now use the `regex` module instead of `re`. +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``. -For example, we can now use character classes to match PEP-3131 compliant Python identifiers. +Any instance of ``Lark`` instantiated with ``regex=True`` will now use +the ``regex`` module instead of ``re``. 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 +48,7 @@ Token .. autoclass:: lark.Token Transformer, Visitor & Interpreter ---------------------------------- +---------------------------------- See :doc:`visitors`. From 2af0ac2087f66b3f1ca7876f8fec286b43b458c1 Mon Sep 17 00:00:00 2001 From: Erez Sh Date: Mon, 17 Aug 2020 15:21:09 +0300 Subject: [PATCH 2/2] Docs: Adjustments --- docs/classes.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/classes.rst b/docs/classes.rst index a880a97..cf72189 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -11,15 +11,14 @@ Lark 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``. - -Any instance of ``Lark`` instantiated with ``regex=True`` will now use -the ``regex`` module instead of ``re``. For example, we can now use -character classes to match PEP-3131 compliant Python identifiers. +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``. + +Any instance of Lark instantiated with ``regex=True`` will use the ``regex`` module instead of ``re``. + +For example, we can use character classes to match PEP-3131 compliant Python identifiers: ::