Skip to content

Commit

Permalink
Merge pull request #1 from qurami/notifications-support
Browse files Browse the repository at this point in the history
Notifications support
  • Loading branch information
giefferre committed Feb 24, 2015
2 parents ceac3ee + d8435ca commit 61c420b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion barrister/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:copyright: 2012 by James Cooper.
:license: MIT, see LICENSE for more details.
"""
__version__ = '0.1.6'
__version__ = '0.1.7'

from barrister.runtime import contract_from_file, idgen_uuid, idgen_seq
from barrister.runtime import RpcException, Server, Filter, HttpTransport, InProcTransport
Expand Down
69 changes: 40 additions & 29 deletions barrister/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ def md5(s):
import md5
return md5.new(s).hexdigest()

native_types = [ "int", "float", "string", "bool" ]
letter = Range("AZaz")
digit = Range("09")
under = Str("_")
period = Str(".")
plain_ident = (letter | under) + Rep(letter | digit | under)
ns_ident = plain_ident + period + plain_ident
ident = plain_ident | ns_ident
arr_ident = Str("[]") + ident
space = Any(" \t\n\r")
space_tab = Any(" \t")
comment = Str("// ") | Str("//")
type_opts = Str("[") + Rep(AnyBut("{}]\n")) + Str("]")
namespace = Str("namespace") + Rep(space_tab) + plain_ident
import_stmt = Str("import") + Rep(space_tab) + Str('"') + Rep(AnyBut("\"\r\n")) + Str('"')
native_types = [ "int", "float", "string", "bool" ]
void_func_types = [ "\r\n", "\n" ]
letter = Range("AZaz")
digit = Range("09")
under = Str("_")
period = Str(".")
plain_ident = (letter | under) + Rep(letter | digit | under)
ns_ident = plain_ident + period + plain_ident
ident = plain_ident | ns_ident
arr_ident = Str("[]") + ident
space = Any(" \t\n\r")
space_tab = Any(" \t")
comment = Str("// ") | Str("//")
type_opts = Str("[") + Rep(AnyBut("{}]\n")) + Str("]")
namespace = Str("namespace") + Rep(space_tab) + plain_ident
import_stmt = Str("import") + Rep(space_tab) + Str('"') + Rep(AnyBut("\"\r\n")) + Str('"')

def file_paths(fname, search_path=None):
if not search_path and os.environ.has_key("BARRISTER_PATH"):
Expand Down Expand Up @@ -98,9 +99,10 @@ def elem_checksum(elem):
s += "[%s" % f["name"]
for p in f["params"]:
s += "\t%s\t%s" % (p["type"], p["is_array"])
ret = f["returns"]
fs = (ret["type"], ret["is_array"], ret["optional"])
s += "(%s\t%s\t%s)]" % fs
if f.get("returns", None):
ret = f["returns"]
fs = (ret["type"], ret["is_array"], ret["optional"])
s += "(%s\t%s\t%s)]" % fs
s += "\n"
return s
return None
Expand Down Expand Up @@ -465,17 +467,24 @@ def end_return(self, text):
if text.find("[]") == 0:
text = text[2:]
is_array = True
type_name = self.prefix_namespace(text)
self.validate_type_vs_first_pass(type_name)
self.function["returns"] = {
"type" : type_name,
"is_array" : is_array,
"optional" : False }
self.type = self.function["returns"]
self.next_state = "functions"
self.cur["functions"].append(self.function)
self.function = None
self.begin("type-opts")
type_name = self.prefix_namespace(text)
if type_name in void_func_types:
self.type = None
self.next_state = "functions"
self.cur["functions"].append(self.function)
self.function = None
self.begin(self.next_state)
else:
self.validate_type_vs_first_pass(type_name)
self.function["returns"] = {
"type" : type_name,
"is_array" : is_array,
"optional" : False }
self.type = self.function["returns"]
self.next_state = "functions"
self.cur["functions"].append(self.function)
self.function = None
self.begin("type-opts")

def end_type_opts(self, text):
text = text.strip()
Expand Down Expand Up @@ -607,6 +616,8 @@ def add_comment_block(self, text):
(arr_ident, end_param),
(space, IGNORE) ]),
State('function-return', [
(Str("\r\n"), end_return),
(Str("\n"), end_return),
(space, IGNORE),
(ident, end_return),
(arr_ident, end_return) ]),
Expand Down
7 changes: 7 additions & 0 deletions barrister/test/idl/including-notifications.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface MyInterface {
// This is a "notification" method
NotifyMe(message string)

// This is a "regular" method
ARegularMethod(param1 string, param2 string) bool
}
10 changes: 10 additions & 0 deletions barrister/test/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,15 @@ def test_file_paths(self):
paths = file_paths(test[0], test[1])
self.assertEquals(test[2], paths)

def test_notification_type(self):
idl = """interface FooService {
notifyThis(s string)
}"""
expected = [ { "name" : "FooService", "type" : "interface", "comment" : "",
"functions" : [
{ "name" : "notifyThis", "comment" : "",
"params" : [ { "type" : "string", "name" : "s", "is_array": False } ] } ] } ]
self.assertEquals(expected, parse(idl, add_meta=False))

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion idl_parse_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# files that should parse
okIdl=("project2.idl" "ok-service.idl")
okIdl=("project2.idl" "ok-service.idl" "including-notifications.idl")

# files that should not parse
badIdl=("project-with-ns.idl" "broken1.idl" "invalid-service.idl" "bad-circle.idl")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='barrister',
version='0.1.6',
version='0.1.7',
url='https://github.com/coopernurse/barrister',
scripts=['bin/barrister'],
packages=['barrister',],
Expand Down

0 comments on commit 61c420b

Please sign in to comment.