aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/rparse.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-28 17:12:39 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-28 17:12:39 +1200
commita779aac9db96b05acb2c4e1b62417bbf37f160f8 (patch)
treec3ef6618b0203db10d9edcea879f8ce817be9244 /libpathod/rparse.py
parent5fc2a63781e554030da9877e8ee56eccc4c873f6 (diff)
downloadmitmproxy-a779aac9db96b05acb2c4e1b62417bbf37f160f8.tar.gz
mitmproxy-a779aac9db96b05acb2c4e1b62417bbf37f160f8.tar.bz2
mitmproxy-a779aac9db96b05acb2c4e1b62417bbf37f160f8.zip
Make specification language more terse, and more regular.
Diffstat (limited to 'libpathod/rparse.py')
-rw-r--r--libpathod/rparse.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 5c6d0257..18d05a69 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -15,6 +15,9 @@ class ParseException(Exception):
def marked(self):
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
+ def __str__(self):
+ return self.msg
+
class ServerError(Exception): pass
@@ -41,16 +44,17 @@ v_integer = pp.Regex(r"[+-]?\d+")\
.setName("integer")\
.setParseAction(lambda toks: int(toks[0]))
-v_string = pp.MatchFirst(
+
+v_literal = pp.MatchFirst(
[
pp.QuotedString("\"", escChar="\\", unquoteResults=True),
pp.QuotedString("'", escChar="\\", unquoteResults=True),
]
)
-v_literal = pp.MatchFirst(
+v_naked_literal = pp.MatchFirst(
[
- v_string,
+ v_literal,
pp.Word("".join(i for i in pp.printables if i not in ",:"))
]
)
@@ -121,6 +125,13 @@ class ValueLiteral:
return self.val
+class ValueNakedLiteral(ValueLiteral):
+ @classmethod
+ def expr(klass):
+ e = v_naked_literal.copy()
+ return e.setParseAction(lambda x: klass(*x))
+
+
class ValueGenerate:
UNITS = dict(
b = 1024**0,
@@ -163,7 +174,7 @@ class ValueFile:
@classmethod
def expr(klass):
e = pp.Literal("<").suppress()
- e = e + v_literal
+ e = e + v_naked_literal
return e.setParseAction(lambda x: klass(*x))
def get_generator(self, settings):
@@ -197,7 +208,7 @@ class Body:
@classmethod
def expr(klass):
- e = pp.Literal("b:").suppress()
+ e = pp.Literal("b").suppress()
e = e + Value
return e.setParseAction(lambda x: klass(*x))
@@ -208,7 +219,7 @@ class _Pause:
@classmethod
def expr(klass):
- e = pp.Literal("p%s:"%klass.sub).suppress()
+ e = pp.Literal("p%s"%klass.sub).suppress()
e = e + pp.MatchFirst(
[
v_integer,
@@ -273,7 +284,7 @@ class Header:
@classmethod
def expr(klass):
- e = pp.Literal("h:").suppress()
+ e = pp.Literal("h").suppress()
e += Value
e += pp.Literal(":").suppress()
e += Value
@@ -294,7 +305,7 @@ class Code:
def expr(klass):
e = v_integer
e = e + pp.Optional(
- pp.Literal(":").suppress() + Value
+ Value
)
return e.setParseAction(lambda x: klass(*x))