Skip to content

Commit

Permalink
Merge pull request #64 from mfine/mfine-latex-generator
Browse files Browse the repository at this point in the history
LaTeX generation
  • Loading branch information
mookerji committed Mar 31, 2015
2 parents 806bdb3 + 9bd90f9 commit 5733d67
Show file tree
Hide file tree
Showing 16 changed files with 404 additions and 181 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ coverage.xml
docs/_build/

# PyBuilder
target/
target/

# LaTeX output
sbp_out.*
81 changes: 0 additions & 81 deletions docs/message_descs.tex

This file was deleted.

21 changes: 0 additions & 21 deletions docs/messages_table.tex

This file was deleted.

Binary file added docs/sbp.pdf
Binary file not shown.
65 changes: 0 additions & 65 deletions docs/sbp_base.tex

This file was deleted.

26 changes: 17 additions & 9 deletions generator/sbp/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sbp.specs.yaml2 as yaml
import sbp.targets.python as py
import sbp.targets.c as c
import sbp.targets.latex as tex

def get_args():
parser = argparse.ArgumentParser(description='Swift Navigation SBP generator.')
Expand All @@ -39,6 +40,9 @@ def get_args():
parser.add_argument('--c',
action="store_true",
help='Target language: C.')
parser.add_argument('--latex',
action="store_true",
help='Target language: LaTeX.')
parser.add_argument('-v',
'--verbose',
action="store_true",
Expand All @@ -54,7 +58,7 @@ def main():
# Parse and validate arguments.
args = get_args().parse_args()
verbose = args.verbose
assert args.python or args.c, "Please specify a target language."
assert args.python or args.c or args.latex, "Please specify a target language."
input_file = os.path.abspath(args.input_file[0])
assert len(args.input_file) == 1
assert os.path.exists(input_file), \
Expand All @@ -71,14 +75,18 @@ def main():
print "Writing to %s" % output_dir
# for fname, spec in file_index.items():
# print yaml.parse_spec(spec)
for fname, spec in file_index.items():
parsed = yaml.parse_spec(spec)
if not parsed.render_source:
continue
if args.python:
py.render_source(output_dir, parsed)
if args.c:
c.render_source(output_dir, parsed)
if args.latex:
parsed = [yaml.parse_spec(spec) for spec in file_index.values()]
tex.render_source(output_dir, parsed)
else:
for fname, spec in file_index.items():
parsed = yaml.parse_spec(spec)
if not parsed.render_source:
continue
if args.python:
py.render_source(output_dir, parsed)
elif args.c:
c.render_source(output_dir, parsed)
except KeyboardInterrupt:
pass

Expand Down
7 changes: 5 additions & 2 deletions generator/sbp/specs/yaml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def mk_package(contents):
description=description,
includes=include,
definitions=resolved,
render_source=contents.get('render_source', True))
render_source=contents.get('render_source', True),
stable=contents.get('stable', False),
public=contents.get('public', False))
def mk_definition(defn):
assert len(defn) == 1
identifier, contents = defn.items()[0]
Expand All @@ -129,7 +131,8 @@ def mk_definition(defn):
short_desc=contents.get('short_desc', None),
desc=contents.get('desc', None),
type_id=contents.get('type'),
fields=fs))
fields=fs,
public=contents.get('public', False)))

def mk_field(field):
assert len(field) == 1
Expand Down
2 changes: 2 additions & 0 deletions generator/sbp/specs/yaml_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
{Optional('id'): sbp_identifier,
Optional('short_desc'): description,
Optional('desc'): description,
Optional('public'): bool,
Optional('size'): size,
Optional('type'): type_identifier,
Optional('fields'): [field]}})
package_schema = Schema({Optional('package'): identifier,
Optional('description'): description,
Optional('render_source'): bool,
Optional('stable'): bool,
Optional('public'): bool,
Optional('include'): include,
Optional('definitions'): [definition]})
7 changes: 5 additions & 2 deletions generator/sbp/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class PackageSpecification(object):
"""

def __init__(self, identifier=None, description=None, includes=[],
definitions=[], render_source=True):
definitions=[], render_source=True, stable=False, public=False):
self.identifier = identifier
self.description = description
self.includes = includes
self.definitions = definitions
self.render_source = render_source
self.stable = stable
self.public = public
self.creation_timestamp = str(datetime.datetime.now())

@property
Expand Down Expand Up @@ -69,13 +71,14 @@ def __repr__(self):
class Definition(object):
def __init__(self, identifier=None,
sbp_id=None, short_desc=None, desc=None, type_id=None,
fields=[]):
fields=[], public=False):
self.identifier = identifier
self.sbp_id = sbp_id
self.short_desc = short_desc
self.desc = desc
self.type_id = type_id
self.fields = fields
self.public = public
self.static = True

@property
Expand Down
Loading

0 comments on commit 5733d67

Please sign in to comment.