diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63d1d95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.tar.gz +bin/* +*.pyc diff --git a/NaCl.py b/NaCl.py index 6a3efd9..60f9ae4 100755 --- a/NaCl.py +++ b/NaCl.py @@ -1,10 +1,10 @@ -#! /usr/local/bin/python - +#! /usr/bin/env python +import sys +sys.path.append('bin') from antlr4 import * from NaClLexer import * from NaClParser import * from NaClVisitor import * -import sys import os import pystache @@ -293,7 +293,7 @@ def process(self): # Then this element is an obj and other assignments can add to this element # We need to validate that no other assignments are overwriting one of the element's # values: - + self.process_obj(self.members, self.ctx.value().obj()) self.process_assignments() @@ -343,7 +343,7 @@ def process(self): class Iface(Typed): def __init__(self, idx, name, ctx, base_type, type_t): super(Iface, self).__init__(idx, name, ctx, base_type, type_t) - + self.config_is_dhcp = False self.config_is_dhcp_fallback = False self.config_is_static = False @@ -491,7 +491,7 @@ def process_members(self): def add_push(self, chain, functions): # chain: string with name of chain # functions: list containing value_name ctxs, where each name corresponds to the name of a NaCl function - + add_snat = False function_names = [] num_functions = len(functions) @@ -552,11 +552,11 @@ def add_iface(self): TEMPLATE_KEY_NAME: self.name, TEMPLATE_KEY_TITLE: self.name.title(), TEMPLATE_KEY_INDEX: self.members.get(IFACE_KEY_INDEX), - + TEMPLATE_KEY_CONFIG_IS_STATIC: self.config_is_static, TEMPLATE_KEY_CONFIG_IS_DHCP: self.config_is_dhcp, TEMPLATE_KEY_CONFIG_IS_DHCP_FALLBACK: self.config_is_dhcp_fallback, - + TEMPLATE_KEY_ADDRESS: self.members.get(IFACE_KEY_ADDRESS), TEMPLATE_KEY_NETMASK: self.members.get(IFACE_KEY_NETMASK), TEMPLATE_KEY_GATEWAY: self.members.get(IFACE_KEY_GATEWAY), @@ -617,7 +617,7 @@ def process_members(self): def process(self): if self.res is None: # Then process - + self.process_ctx() self.process_assignments() self.validate_members() @@ -894,7 +894,7 @@ def add_gateway(self, routes): def process(self): if self.res is None: # Then process: - + self.process_ctx() self.process_assignments() self.validate_and_process_not_route_members() @@ -911,7 +911,7 @@ def process(self): # -------------------- Function -------------------- class Function(Element): - def __init__(self, idx, name, ctx, base_type, type_t, subtype): + def __init__(self, idx, name, ctx, base_type, type_t, subtype): super(Function, self).__init__(idx, name, ctx, base_type) self.type_t = type_t self.subtype = subtype @@ -972,13 +972,13 @@ def handle_input(): # Process / transpile / fill the pystache lists function_elements = [] - + for key, e in elements.iteritems(): if e.base_type != BASE_TYPE_FUNCTION: e.process() else: function_elements.append(e) - + # Have processed all elements except function elements when arrive here for e in function_elements: e.process() @@ -1040,7 +1040,7 @@ def save_element(base_type, ctx): if base_type == BASE_TYPE_UNTYPED_INIT: elements[name] = Untyped(idx, name, ctx, base_type) return - + type_t_ctx = ctx.type_t() type_t = type_t_ctx.getText() @@ -1054,7 +1054,7 @@ def save_element(base_type, ctx): return # BASE_TYPE_TYPED_INIT - + type_t_lower = type_t.lower() if type_t_lower == TYPE_IFACE: elements[name] = Iface(idx, name, ctx, base_type, type_t) @@ -1099,4 +1099,4 @@ def visitFunction(self, ctx): visitor = NaClRecordingVisitor() visitor.visit(tree) -handle_input() \ No newline at end of file +handle_input() diff --git a/README.md b/README.md index d9c46e1..fee8585 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 1. Install antlr4 exactly like described under Quick start: http://www.antlr.org/ 2. `pip install antlr4-python2-runtime` 3. `pip install pystache` -4. Generate python parser / lexer for `NaCl.g4` grammar WITH visitor (NaClVisitor.py): `antlr4 -Dlanguage=Python2 NaCl.g4 -visitor` +4. Generate python parser / lexer for `NaCl.g4` grammar WITH visitor (NaClVisitor.py): `antlr4 -Dlanguage=Python2 NaCl.g4 -visitor -o bin` 5. Make transpiler program executable: `chmod u+x NaCl.py` 6. run with `cat examples/nacl.nacl | ./NaCl.py` 7. For testing, using the `grun` program (alias really) is nice. This requires that you generate the java lexer / parser diff --git a/create_bundle.sh b/create_bundle.sh new file mode 100755 index 0000000..a915503 --- /dev/null +++ b/create_bundle.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +TARFILE="nacl_bin.tar.gz" +tar -zcvf $TARFILE bin +echo -e "> Created $TARFILE" +md5 $TARFILE