Skip to content

Commit

Permalink
More documentation for dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
MGlauer committed Jul 18, 2019
1 parent a4cfebf commit a5116e1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/omi/dialects/base/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,59 @@ class Dialect:
_renderer = Renderer

def compile(self, obj: OEPMetadata, *args, **kwargs):
"""
Compiles the passed :class:`~omi.structure.OEPMetadata`-object into the
structure fitting for this dialect
Parameters
----------
obj
The :class:`~omi.structure.OEPMetadata`-object to compile
Returns
-------
"""
c = self._compiler()
return c.visit(obj, *args, **kwargs)

def parse(self, string: str, *args, **kwargs) -> OEPMetadata:
"""
Loads the passed string into an
:class:`~omi.structure.OEPMetadata`-object.
Parameters
----------
string
The string to parse
Returns
-------
The :class:`~omi.structure.OEPMetadata`-object represented by `string`
"""
p = self._parser()
return p.parse_from_string(string, *args, **kwargs)

def render(self, structure, *args, **kwargs) -> str:
"""
Turns the structure used by this dialect into a string
Parameters
----------
structure
The structure to stringify
Returns
-------
A string representation of `structure`
"""
r = self._renderer()
return r.render(structure, *args, **kwargs)

def compile_and_render(self, obj: OEPMetadata, *args, **kwargs):
"""
Combination of :func:`~omi.dialects.base.dialect.Dialect.compile` and :func:`~omi.dialects.base.dialect.Dialect.render`.
"""
c = self._compiler()
r = self._renderer()
compiled = c.visit(obj, *args, **kwargs)
Expand Down
3 changes: 1 addition & 2 deletions src/omi/dialects/base/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def load_string(self, string: str, *args, **kwargs):
Returns
-------
Translates the passed string into the format used as input for
this parser
Translates the passed string into the format used as input for this parser
"""
raise NotImplementedError

Expand Down

0 comments on commit a5116e1

Please sign in to comment.