From 11ef9a18fe1ee0d02717a906b8f4bbf91f1c9640 Mon Sep 17 00:00:00 2001 From: Erez Sh Date: Wed, 1 Jul 2020 16:53:08 +0300 Subject: [PATCH] Improved documentation --- docs/classes.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/classes.md b/docs/classes.md index c901a44..8b32801 100644 --- a/docs/classes.md +++ b/docs/classes.md @@ -8,11 +8,23 @@ This page details the important classes in Lark. The Lark class is the main interface for the library. It's mostly a thin wrapper for the many different parsers, and for the tree constructor. -#### \_\_init\_\_(self, grammar_string, **options) - +#### Lark.\_\_init\_\_ +```python +def __init__(self, grammar_string, **options): ... +``` Creates an instance of Lark with the given grammar -#### open(cls, grammar_filename, rel_to=None, **options) +Example: + +```python + >>> Lark(r'''start: "foo" ''') + Lark(...) +``` + +#### Lark.open +```python +def open(cls, grammar_filename, rel_to=None, **options): ... +``` Creates an instance of Lark with the grammar given by its filename @@ -25,7 +37,7 @@ Example: Lark(...) ``` -#### Lark.parser +#### Lark.parse ```python def parse(self, text, start=None, on_error=None): ... @@ -45,6 +57,12 @@ Parameters: (See `examples/error_puppet.py` for an example of how to use `on_error`.) +Example: +```python + >>> Lark(r'''start: "hello" " "+ /\w+/ ''').parse('hello kitty') + Tree(start, [Token(__ANON_0, 'kitty')]) +``` + #### Lark.save / Lark.load ```python def save(self, f): ...