Skip to content

Commit

Permalink
A few more documentation/example
Browse files Browse the repository at this point in the history
  • Loading branch information
leandron committed Apr 28, 2017
1 parent 48700cd commit de6272d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc']
extensions = ['sphinx.ext.autodoc', 'sphinxcontrib.spelling']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
18 changes: 16 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ It is easy to obtain the latest released version via ``pip``::

pip install steinlib

Usage
=====
Basic Usage
============

In order to use the parsed structures, two main components are required:

- A *parser*, that will be responsible for parsing the structure, and;
- A *instance*, where the parser will invoke callbacks when known structures are found

Expand All @@ -35,8 +36,10 @@ So, let's see an example about how it works.
Starting with an STP file available on Steinlib official website:

.. literalinclude:: ../../examples/hello.stp
:linenos:

It is possible to observe this file contains three main components:

- a **header line**;
- a set of delimited **sections** and;
- the **end of file** marker.
Expand All @@ -45,4 +48,15 @@ This *parser* will identify all these small pieces of the STP file and use it to
trigger functions on your *instance*. This is the key concept used to create
this module.

The script below provides some initial examples about how these ``callback`` methods
works:

.. literalinclude:: ../../examples/hello_steinlib.py
:linenos:

For each identified structure, the appropriate method will be called in the *instance*
object, with the standard parameters:

- ``raw_args`` is the actual full line from the input stream
- ``list_args`` contains the extracted and converted parameters from the current line

6 changes: 5 additions & 1 deletion examples/hello_steinlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ class MySteinlibInstance(SteinlibInstance):
This is my first steinlib parser!
"""

def comment(self, raw_args, lis_args):
def comment(self, raw_args, list_args):
print "Comment section found"

def comment__end(self, raw_args, list_args):
print "Comment section end"

def coordinates(self, raw_args, list_args):
print "Coordinates section found"

Expand All @@ -35,3 +38,4 @@ def terminals(self, raw_args, list_args):
with open(sys.argv[1]) as my_file:
my_parser = SteinlibParser(my_file, my_class)
my_parser.parse()

0 comments on commit de6272d

Please sign in to comment.