Skip to content

Commit

Permalink
typing in grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Jul 23, 2022
1 parent 3b70d77 commit 829bbf8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pyleri/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def export_js(
self,
js_module_name=JS_MODULE_NAME,
js_template=JS_ES6_IMPORT_EXPORT_TEMPLATE,
js_indent=JS_INDENTATION):
js_indent=JS_INDENTATION) -> str:
"""Export the grammar to a JavaScript file which can be
used with the js-lrparsing module.
Expand Down Expand Up @@ -405,7 +405,7 @@ def export_py(
self,
py_module_name=PY_MODULE_NAME,
py_template=PY_TEMPLATE,
py_indent=PY_INDENTATION):
py_indent=PY_INDENTATION) -> str:
"""Export the grammar to a python file which can be
used with the pyleri module. This can be useful when python code
if used to auto-create a grammar and an export of the final result is
Expand Down Expand Up @@ -449,7 +449,11 @@ def export_py(
' '.join(['from', py_module_name, 'import', n])
for n in classes if n != 'Rule'])))

def export_c(self, target=C_TARGET, c_indent=C_INDENTATION, headerf=None):
def export_c(
self,
target=C_TARGET,
c_indent=C_INDENTATION,
headerf=None) -> str:
"""Export the grammar to a c (source and header) file which can be
used with the libcleri module."""
language = []
Expand Down Expand Up @@ -517,7 +521,7 @@ def export_go(
self,
go_template=GO_TEMPLATE,
go_indent=GO_INDENTATION,
go_package=GO_PACKAGE):
go_package=GO_PACKAGE) -> str:
"""Export the grammar to a Go file which can be
used with the goleri module."""

Expand Down Expand Up @@ -568,7 +572,7 @@ def export_java(
java_template=JAVA_TEMPLATE,
java_indent=JAVA_INDENTATION,
java_package=JAVA_PACKAGE,
is_public=True):
is_public=True) -> str:
"""Export the grammar to a Java file which can be
used with the jleri module."""

Expand Down Expand Up @@ -629,7 +633,7 @@ def export_java(
enums=enum_str,
public='public ' if is_public else '')

def parse(self, string):
def parse(self, string) -> Result:
"""Parse some string to the Grammar.
Returns a nodeResult with the following attributes:
Expand Down Expand Up @@ -692,7 +696,9 @@ def _walk(self, element, pos, tree, rule, is_required):
return element._get_node_result(self, tree, rule, self._s, node)


def create_grammar(elem, re_keywords=_RE_KEYWORDS):
def create_grammar(
elem: Element,
re_keywords: re.Pattern = _RE_KEYWORDS) -> Grammar:
class _Grammar(Grammar):
RE_KEYWORDS = _RE_KEYWORDS
START = elem
Expand Down

0 comments on commit 829bbf8

Please sign in to comment.