Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

New thrift parser using ply #36

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools.extension import Extension

install_requires = [
"pyparsing>=2.0.2,<2.1.0",
"ply>=3.4",
]

tornado_requires = [
Expand Down Expand Up @@ -44,7 +44,7 @@
["thriftpy/protocol/cybin/cybin.c"]))

setup(name="thriftpy",
version=__import__('thriftpy').__version__,
version='0.1.9',
description="Pure python implemention of Apache Thrift.",
keywords="thrift python thriftpy",
author="Lx Yu",
Expand Down
4 changes: 2 additions & 2 deletions tests/const.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const i16 NEGATIVE_I16 = -10
const i16 NEGATIVE_DOUBLE = -123.456
const double NEGATIVE_DOUBLE = -123.456

const i16 I16_CONST = 10
const i32 I32_CONST = 100000
Expand All @@ -12,5 +12,5 @@ const list<i32> I32_LIST_CONST = [1, 2, 3]
const list<double> DOUBLE_LIST_CONST = [1.1, 2.2, 3.3]
const list<string> STRING_LIST_CONST = ["hello", "world"]
const list<list<i32>> I32_LIST_LIST_CONST = [[1, 2, 3], [4, 5, 6]]
const list<list<i32>> DOUBLE_LIST_LIST_CONST = [[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]
const list<list<double>> DOUBLE_LIST_LIST_CONST = [[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]
const list<list<string>> STRING_LIST_LIST_CONST = [["hello", "world"], ["foo", "bar"]]
11 changes: 11 additions & 0 deletions tests/parser-cases/json/comments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"includes": [],
"namespaces": {},
"enums": {},
"structs": {},
"unions": {},
"exceptions": {},
"typedefs": {},
"consts": {},
"services": {}
}
18 changes: 18 additions & 0 deletions tests/parser-cases/json/consts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"consts": {
"num1": 1,
"num2": 2000,
"num3": 30000000000,
"str": "hello",
"lst": [1, 2, 3],
"mp": {"key": "val"}
},
"includes": [],
"namespaces": {},
"enums": {},
"structs": {},
"unions": {},
"exceptions": {},
"typedefs": {},
"services": {}
}
27 changes: 27 additions & 0 deletions tests/parser-cases/json/enums.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"typedefs": {},
"includes": [],
"namespaces": {},
"structs": {},
"unions": {},
"consts": {},
"services": {},
"exceptions": {},
"enums": {
"Enum1": {
"A": 1,
"B": 2,
"C": 3
},
"Enum2": {
"A": 1,
"B": 2,
"C": 3
},
"Enum3": {
"A": 0,
"B": 1,
"C": 2
}
}
}
13 changes: 13 additions & 0 deletions tests/parser-cases/json/escape.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"consts": {
"name": "\t\n\r\\"
},
"includes": [],
"namespaces": {},
"enums": {},
"structs": {},
"unions": {},
"exceptions": {},
"typedefs": {},
"services": {}
}
28 changes: 28 additions & 0 deletions tests/parser-cases/json/exceptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"includes": [],
"namespaces": {},
"typedefs": {},
"enums": {},
"unions": {},
"consts": {},
"services": {},
"exceptions": {
"SyntaxError": [
{
"id": 1,
"name": "lineNumber",
"type": "i32",
"value": null,
"requirement": null
},
{
"id": 2,
"name": "errorMessage",
"type": "string",
"value": null,
"requirement": null
}
]
},
"structs": {}
}
11 changes: 11 additions & 0 deletions tests/parser-cases/json/includes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"includes": ["shared.thrift", "sample.thrift"],
"namespaces": {},
"enums": {},
"structs": {},
"unions": {},
"exceptions": {},
"typedefs": {},
"consts": {},
"services": {}
}
11 changes: 11 additions & 0 deletions tests/parser-cases/json/namespaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"namespaces": {"SAMPLE": "php", "sample": "py"},
"includes": [],
"enums": {},
"structs": {},
"unions": {},
"exceptions": {},
"typedefs": {},
"consts": {},
"services": {}
}
57 changes: 57 additions & 0 deletions tests/parser-cases/json/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"includes": [],
"namespaces": {},
"typedefs": {},
"enums": {},
"unions": {},
"consts": {},
"exceptions": {
"NetError": []
},
"structs": {},
"services": {
"SMS": {
"extends": "BasicService",
"apis": {
"get_message_by_id": {
"name": "get_message_by_id",
"type": "string",
"oneway": false,
"throws": [],
"fields": [
{
"id": 1,
"name": "id",
"type": "i32",
"value": null,
"requirement": "required"
}
]
},
"send": {
"name": "send",
"type": "void",
"oneway": true,
"throws": [
{
"type": "NetError",
"id": 1,
"value": null,
"requirement": null,
"name": "net_error"
}
],
"fields": [
{
"id": 1,
"name": "to",
"type": "string",
"value": null,
"requirement": "required"
}
]
}
}
}
}
}
28 changes: 28 additions & 0 deletions tests/parser-cases/json/structs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"includes": [],
"namespaces": {},
"typedefs": {},
"enums": {},
"unions": {},
"consts": {},
"services": {},
"exceptions": {},
"structs": {
"Person": [
{
"id": 1,
"name": "name",
"type": "string",
"value": null,
"requirement": null
},
{
"id": 2,
"name": "age",
"type": "i32",
"value": null,
"requirement": null
}
]
}
}
150 changes: 150 additions & 0 deletions tests/parser-cases/json/tutorial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"namespaces": {
"tutorial": "perl"
},
"includes": [
"shared.thrift"
],
"services": {
"Calculator": {
"extends": "shared.SharedService",
"apis": {
"add": {
"fields": [
{
"requirement": null,
"type": "i32",
"id": 1,
"value": null,
"name": "num1"
},
{
"requirement": null,
"type": "i32",
"id": 2,
"value": null,
"name": "num2"
}
],
"oneway": false,
"type": "i32",
"name": "add",
"throws": []
},
"ping": {
"fields": [],
"oneway": false,
"type": "void",
"name": "ping",
"throws": []
},
"calculate": {
"fields": [
{
"requirement": null,
"type": "i32",
"id": 1,
"value": null,
"name": "logid"
},
{
"requirement": null,
"type": "Work",
"id": 2,
"value": null,
"name": "w"
}
],
"oneway": false,
"type": "i32",
"name": "calculate",
"throws": [
{
"requirement": null,
"type": "InvalidOperation",
"id": 1,
"value": null,
"name": "ouch"
}
]
},
"zip": {
"fields": [],
"oneway": true,
"type": "void",
"name": "zip",
"throws": []
}
}
}
},
"unions": {},
"typedefs": {
"MyInteger": "i32"
},
"consts": {
"MAPCONSTANT": {
"goodnight": "moon",
"hello": "world"
},
"INT32CONSTANT": 9853
},
"exceptions": {
"InvalidOperation": [
{
"requirement": null,
"type": "i32",
"id": 1,
"value": null,
"name": "what"
},
{
"requirement": null,
"type": "string",
"id": 2,
"value": null,
"name": "why"
}
]
},
"enums": {
"Operation": {
"MULTIPLY": 3,
"ADD": 1,
"SUBTRACT": 2,
"DIVIDE": 4
}
},
"structs": {
"Work": [
{
"requirement": null,
"type": "i32",
"id": 1,
"value": 0,
"name": "num1"
},
{
"requirement": null,
"type": "i32",
"id": 2,
"value": null,
"name": "num2"
},
{
"requirement": null,
"type": "Operation",
"id": 3,
"value": null,
"name": "op"
},
{
"requirement": "optional",
"type": "string",
"id": 4,
"value": null,
"name": "comment"
}
]
}
}
Loading