Skip to content

Commit

Permalink
Merge pull request #37 from AndreasAakesson/master
Browse files Browse the repository at this point in the history
Output from antlr is now in bin dir. Added build script for bundle
  • Loading branch information
AnnikaH authored Nov 21, 2017
2 parents 1c53de3 + cf0bbe8 commit 6e7546c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tar.gz
bin/*
*.pyc
32 changes: 16 additions & 16 deletions NaCl.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -1099,4 +1099,4 @@ def visitFunction(self, ctx):
visitor = NaClRecordingVisitor()
visitor.visit(tree)

handle_input()
handle_input()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions create_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

TARFILE="nacl_bin.tar.gz"
tar -zcvf $TARFILE bin
echo -e "> Created $TARFILE"
md5 $TARFILE

0 comments on commit 6e7546c

Please sign in to comment.