From 3ec7f7d741d596490844a79ae4283221d685360b Mon Sep 17 00:00:00 2001 From: AnjaBruls <39908703+AnjaBruls@users.noreply.github.com> Date: Tue, 18 Dec 2018 14:52:41 +0100 Subject: [PATCH 1/2] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e9742a6..795f078 100644 --- a/README.md +++ b/README.md @@ -422,7 +422,7 @@ def view_parse_tree(res): if __name__ == '__main__': # Compile your grammar by creating an instance of the Grammar Class: my_grammar = MyGrammar() - res = my_grammar.parse('hi "siri" bye "siri"') + res = my_grammar.parse('hi "pyleri" bye "pyleri"') # The parse tree is visualized as a JSON object: print(json.dumps(view_parse_tree(res), indent=2)) ``` @@ -436,7 +436,7 @@ Part of the output is shown below. "end": 23, "name": "START", "element": "Repeat", - "string": "hi \"pyleri\" hi \"pyleri\"", + "string": "hi \"pyleri\" bye \"pyleri\"", "children": [ { "start": 0, From 16d320bb9263f764bb982b4069ab8946c554af3c Mon Sep 17 00:00:00 2001 From: AnjaBruls <39908703+AnjaBruls@users.noreply.github.com> Date: Tue, 18 Dec 2018 16:34:19 +0100 Subject: [PATCH 2/2] Update Readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 795f078..650c8e1 100644 --- a/README.md +++ b/README.md @@ -480,13 +480,13 @@ A node contains 5 properties that will be explained next: - `start` property returns the start of the node object. - `end` property returns the end of the node object. -- `element` returns the type of [Element](#elements) (e.g. Repeat, Sequence, Keyword, etc.). An element can be assigned to a variable; for instance in the example above `Keyword('hi')` was assigned to `k_hi`. With `element.name` the assigned name `k_hi` will be returned. Note that it is not a given that an element is named; in our example `Sequence` was not assigned, thus in this case the element has no attribute `name`. +- `element` returns the [Element](#elements)'s type (e.g. Repeat, Sequence, Keyword, etc.). An element can be assigned to a variable; for instance in the example above `Keyword('hi')` was assigned to `k_hi`. With `element.name` the assigned name `k_hi` will be returned. Note that it is not a given that an element is named; in our example `Sequence` was not assigned, thus in this case the element has no attribute `name`. - `string` returns the string that is parsed. - `children` can return a node object containing deeper layered nodes provided that there are any. In our example the root node has an element type `Repeat()`, starts at 0 and ends at 24, and it has two `children`. These children are node objects that have both an element type `Sequence`, start at 0 and 12 respectively, and so on. ### Expecting -`expecting` returns a Python set() containing elements which pyleri expects at `pos`. Even if `is_valid` is true there might be elements in this set, for example when an `Optional()` element could be added to the string. Expecting is useful if you want to implement things like auto-completion, syntax error handling, auto-syntax-correction etc. The following example will illustrate a way of implementation. +`expecting` returns a Python set() containing elements which pyleri expects at `pos`. Even if `is_valid` is true there might be elements in this set, for example when an `Optional()` element could be added to the string. "Expecting" is useful if you want to implement things like auto-completion, syntax error handling, auto-syntax-correction etc. The following example will illustrate a way of implementation. Example: ```python @@ -582,7 +582,7 @@ Expected: (2) bye ``` -In the above example we parsed an invalid string according to the grammar class. The `auto-correction()` method that we built for this example combines all properties from the `parse()` to create a valid string. The output shows every recursion of the `auto-correction()` method and prints successively the set of expected elements. It takes one randomly and adds it to the string. When the string corresponds to the grammar, the property `is_valid` will return `True`. Notably the `expecting` property still contains elements even if the `is_valid` returned `True`. The reason in this example is because of the [Repeat](#repeat) element. +In the above example we parsed an invalid string according to the grammar class. The `auto-correction()` method that we built for this example combines all properties from the `parse()` to create a valid string. The output shows every recursion of the `auto-correction()` method and prints successively the set of expected elements. It takes one randomly and adds it to the string. When the string corresponds to the grammar, the property `is_valid` will return `True`. Notably the `expecting` property still contains elements even if the `is_valid` returned `True`. The reason in this example is due to the [Repeat](#repeat) element. ## Elements Pyleri has several elements which are all subclasses of [Element](#element) and can be used to create a grammar.