summaryrefslogtreecommitdiff
path: root/scss/src
diff options
context:
space:
mode:
authorEevee <eevee.git@veekun.com>2013-05-16 18:42:09 -0700
committerEevee <eevee.git@veekun.com>2013-05-23 13:43:24 -0700
commite6f5550dc856cf21a333cb9bd25e884865fa6f81 (patch)
tree2e7ddc3ff5217989e725e32222371c3bd68b2276 /scss/src
parent5624da057f756d84a8a7c63c912887ebc3195825 (diff)
downloadpyscss-e6f5550dc856cf21a333cb9bd25e884865fa6f81.tar.gz
Remove rule and library from the expression grammar.
Diffstat (limited to 'scss/src')
-rw-r--r--scss/src/grammar/grammar.g124
-rw-r--r--scss/src/grammar/grammar.py148
2 files changed, 78 insertions, 194 deletions
diff --git a/scss/src/grammar/grammar.g b/scss/src/grammar/grammar.g
index c8ab79f..0057dce 100644
--- a/scss/src/grammar/grammar.g
+++ b/scss/src/grammar/grammar.g
@@ -1,39 +1,5 @@
# python yapps2.py grammar.g grammar.py
-
-_units = ['em', 'ex', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'deg', 'rad'
- 'grad', 'ms', 's', 'hz', 'khz', '%']
-_inv = lambda s: s
-ParserValue = lambda s: s
-NumberValue = lambda s: float(s)
-StringValue = lambda s: s
-QuotedStringValue = lambda s: s
-BooleanValue = lambda s: bool(s)
-ColorValue = lambda s: s
-class ListValue():
- def __init__(self, v):
- if isinstance(v, self.__class__):
- self.v = v
- else:
- self.v = {0: v}
- def first(self):
- return self.v[0]
- def __len__(self):
- return len(self.v)
-
-
-def _reorder_list(lst):
- return dict((i if isinstance(k, int) else k, v) for i, (k, v) in enumerate(sorted(lst.items())))
-
-
-def interpolate(v, R, library):
- return v
-
-
-def call(fn, args, R, library, function=True):
- print 'call: ', fn, args
- return args
-
################################################################################
#'(?<!\\s)(?:' + '|'.join(_units) + ')(?![-\\w])'
## Grammar compiled using Yapps:
@@ -68,57 +34,57 @@ parser Calculator:
token VAR: "\$[-a-zA-Z0-9_]+"
token FNCT: "[-a-zA-Z_][-a-zA-Z0-9_]*(?=\()"
token ID: "[-a-zA-Z_][-a-zA-Z0-9_]*"
- rule goal<<R>>: expr_lst<<R>> {{ v = expr_lst }}
+ rule goal: expr_lst {{ v = expr_lst }}
END {{ return v }}
- rule expr<<R>>: and_test<<R>> {{ v = and_test }}
+ rule expr: and_test {{ v = and_test }}
(
- OR and_test<<R>> {{ v = AnyOp(v, and_test) }}
+ OR and_test {{ v = AnyOp(v, and_test) }}
)* {{ return v }}
- rule and_test<<R>>: not_test<<R>> {{ v = not_test }}
+ rule and_test: not_test {{ v = not_test }}
(
- AND not_test<<R>> {{ v = AllOp(v, not_test) }}
+ AND not_test {{ v = AllOp(v, not_test) }}
)* {{ return v }}
- rule not_test<<R>>: comparison<<R>> {{ return comparison }}
+ rule not_test: comparison {{ return comparison }}
|
- NOT not_test<<R>> {{ return NotOp(not_test) }}
- rule comparison<<R>>: a_expr<<R>> {{ v = a_expr }}
+ NOT not_test {{ return NotOp(not_test) }}
+ rule comparison: a_expr {{ v = a_expr }}
(
- LT a_expr<<R>> {{ v = BinaryOp(operator.lt, v, a_expr) }}
+ LT a_expr {{ v = BinaryOp(operator.lt, v, a_expr) }}
|
- GT a_expr<<R>> {{ v = BinaryOp(operator.gt, v, a_expr) }}
+ GT a_expr {{ v = BinaryOp(operator.gt, v, a_expr) }}
|
- LE a_expr<<R>> {{ v = BinaryOp(operator.le, v, a_expr) }}
+ LE a_expr {{ v = BinaryOp(operator.le, v, a_expr) }}
|
- GE a_expr<<R>> {{ v = BinaryOp(operator.ge, v, a_expr) }}
+ GE a_expr {{ v = BinaryOp(operator.ge, v, a_expr) }}
|
- EQ a_expr<<R>> {{ v = BinaryOp(operator.eq, v, a_expr) }}
+ EQ a_expr {{ v = BinaryOp(operator.eq, v, a_expr) }}
|
- NE a_expr<<R>> {{ v = BinaryOp(operator.ne, v, a_expr) }}
+ NE a_expr {{ v = BinaryOp(operator.ne, v, a_expr) }}
)* {{ return v }}
- rule a_expr<<R>>: m_expr<<R>> {{ v = m_expr }}
+ rule a_expr: m_expr {{ v = m_expr }}
(
- ADD m_expr<<R>> {{ v = BinaryOp(operator.add, v, m_expr) }}
+ ADD m_expr {{ v = BinaryOp(operator.add, v, m_expr) }}
|
- SUB m_expr<<R>> {{ v = BinaryOp(operator.sub, v, m_expr) }}
+ SUB m_expr {{ v = BinaryOp(operator.sub, v, m_expr) }}
)* {{ return v }}
- rule m_expr<<R>>: u_expr<<R>> {{ v = u_expr }}
+ rule m_expr: u_expr {{ v = u_expr }}
(
- MUL u_expr<<R>> {{ v = BinaryOp(operator.mul, v, u_expr) }}
+ MUL u_expr {{ v = BinaryOp(operator.mul, v, u_expr) }}
|
- DIV u_expr<<R>> {{ v = BinaryOp(operator.div, v, u_expr) }}
+ DIV u_expr {{ v = BinaryOp(operator.div, v, u_expr) }}
)* {{ return v }}
- rule u_expr<<R>>: SIGN u_expr<<R>> {{ return UnaryOp(operator.neg, u_expr) }}
+ rule u_expr: SIGN u_expr {{ return UnaryOp(operator.neg, u_expr) }}
|
- ADD u_expr<<R>> {{ return UnaryOp(operator.pos, u_expr) }}
+ ADD u_expr {{ return UnaryOp(operator.pos, u_expr) }}
|
- atom<<R>> {{ return atom }}
- rule atom<<R>>: LPAR expr_lst<<R>> RPAR {{ return expr_lst }}
+ atom {{ return atom }}
+ rule atom: LPAR expr_lst RPAR {{ return expr_lst }}
|
ID {{ return Literal(StringValue(ID)) }}
|
FNCT {{ v = ArgspecLiteral([]) }}
LPAR [
- argspec<<R>> {{ v = argspec }}
+ argspec {{ v = argspec }}
] RPAR {{ return CallOp(FNCT, v) }}
|
NUM [
@@ -134,53 +100,29 @@ parser Calculator:
COLOR {{ return Literal(ColorValue(ParserValue(COLOR))) }}
|
VAR {{ return Variable(VAR) }}
- rule argspec<<R>>: argspec_item<<R>> {{ v = [argspec_item] }}
+ rule argspec: argspec_item {{ v = [argspec_item] }}
(
COMMA
- argspec_item<<R>> {{ v.append(argspec_item) }}
+ argspec_item {{ v.append(argspec_item) }}
)* {{ return ArgspecLiteral(v) }}
- rule argspec_item<<R>>: {{ var = None }}
+ rule argspec_item: {{ var = None }}
[
VAR
[ ":" {{ var = VAR }}
] {{ else: self._rewind() }}
]
- expr_slst<<R>> {{ return (var, expr_slst) }}
- rule expr_lst<<R>>: expr_slst<<R>> {{ v = [expr_slst] }}
+ expr_slst {{ return (var, expr_slst) }}
+ rule expr_lst: expr_slst {{ v = [expr_slst] }}
(
COMMA
- expr_slst<<R>> {{ v.append(expr_slst) }}
+ expr_slst {{ v.append(expr_slst) }}
)* {{ return ListLiteral(v) if len(v) > 1 else v[0] }}
- rule expr_slst<<R>>: expr<<R>> {{ v = [expr] }}
+ rule expr_slst: expr {{ v = [expr] }}
(
- expr<<R>> {{ v.append(expr) }}
+ expr {{ v.append(expr) }}
)* {{ return ListLiteral(v, comma=False) if len(v) > 1 else v[0] }}
%%
expr_lst_rsts_ = None
- def __init__(self, scanner, library):
- self._library = library
- super(Calculator, self).__init__(scanner)
-
-
### Grammar ends.
################################################################################
-
-P = Calculator(CalculatorScanner())
-
-
-def parse(rule, text, *args):
- P.reset(text)
- return wrap_error_reporter(P, rule, *args)
-
-
-if __name__ == '__main__':
- while True:
- try:
- s = raw_input('>>> ')
- except EOFError:
- break
- if not s.strip():
- break
- print parse('goal', s, None)
- print 'Bye.'
diff --git a/scss/src/grammar/grammar.py b/scss/src/grammar/grammar.py
index 4d347f9..f03f727 100644
--- a/scss/src/grammar/grammar.py
+++ b/scss/src/grammar/grammar.py
@@ -1,39 +1,5 @@
# python yapps2.py grammar.g grammar.py
-
-_units = ['em', 'ex', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'deg', 'rad'
- 'grad', 'ms', 's', 'hz', 'khz', '%']
-_inv = lambda s: s
-ParserValue = lambda s: s
-NumberValue = lambda s: float(s)
-StringValue = lambda s: s
-QuotedStringValue = lambda s: s
-BooleanValue = lambda s: bool(s)
-ColorValue = lambda s: s
-class ListValue():
- def __init__(self, v):
- if isinstance(v, self.__class__):
- self.v = v
- else:
- self.v = {0: v}
- def first(self):
- return self.v[0]
- def __len__(self):
- return len(self.v)
-
-
-def _reorder_list(lst):
- return dict((i if isinstance(k, int) else k, v) for i, (k, v) in enumerate(sorted(lst.items())))
-
-
-def interpolate(v, R, library):
- return v
-
-
-def call(fn, args, R, library, function=True):
- print 'call: ', fn, args
- return args
-
################################################################################
#'(?<!\\s)(?:' + '|'.join(_units) + ')(?![-\\w])'
## Grammar compiled using Yapps:
@@ -89,120 +55,120 @@ class CalculatorScanner(Scanner):
class Calculator(Parser):
- def goal(self, R):
- expr_lst = self.expr_lst(R)
+ def goal(self):
+ expr_lst = self.expr_lst()
v = expr_lst
END = self._scan('END')
return v
- def expr(self, R):
- and_test = self.and_test(R)
+ def expr(self):
+ and_test = self.and_test()
v = and_test
while self._peek(self.expr_rsts) == 'OR':
OR = self._scan('OR')
- and_test = self.and_test(R)
+ and_test = self.and_test()
v = AnyOp(v, and_test)
return v
- def and_test(self, R):
- not_test = self.not_test(R)
+ def and_test(self):
+ not_test = self.not_test()
v = not_test
while self._peek(self.and_test_rsts) == 'AND':
AND = self._scan('AND')
- not_test = self.not_test(R)
+ not_test = self.not_test()
v = AllOp(v, not_test)
return v
- def not_test(self, R):
+ def not_test(self):
_token_ = self._peek(self.not_test_rsts)
if _token_ != 'NOT':
- comparison = self.comparison(R)
+ comparison = self.comparison()
return comparison
else: # == 'NOT'
NOT = self._scan('NOT')
- not_test = self.not_test(R)
+ not_test = self.not_test()
return NotOp(not_test)
- def comparison(self, R):
- a_expr = self.a_expr(R)
+ def comparison(self):
+ a_expr = self.a_expr()
v = a_expr
while self._peek(self.comparison_rsts) in self.comparison_chks:
_token_ = self._peek(self.comparison_chks)
if _token_ == 'LT':
LT = self._scan('LT')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.lt, v, a_expr)
elif _token_ == 'GT':
GT = self._scan('GT')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.gt, v, a_expr)
elif _token_ == 'LE':
LE = self._scan('LE')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.le, v, a_expr)
elif _token_ == 'GE':
GE = self._scan('GE')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.ge, v, a_expr)
elif _token_ == 'EQ':
EQ = self._scan('EQ')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.eq, v, a_expr)
else: # == 'NE'
NE = self._scan('NE')
- a_expr = self.a_expr(R)
+ a_expr = self.a_expr()
v = BinaryOp(operator.ne, v, a_expr)
return v
- def a_expr(self, R):
- m_expr = self.m_expr(R)
+ def a_expr(self):
+ m_expr = self.m_expr()
v = m_expr
while self._peek(self.a_expr_rsts) in self.a_expr_chks:
_token_ = self._peek(self.a_expr_chks)
if _token_ == 'ADD':
ADD = self._scan('ADD')
- m_expr = self.m_expr(R)
+ m_expr = self.m_expr()
v = BinaryOp(operator.add, v, m_expr)
else: # == 'SUB'
SUB = self._scan('SUB')
- m_expr = self.m_expr(R)
+ m_expr = self.m_expr()
v = BinaryOp(operator.sub, v, m_expr)
return v
- def m_expr(self, R):
- u_expr = self.u_expr(R)
+ def m_expr(self):
+ u_expr = self.u_expr()
v = u_expr
while self._peek(self.m_expr_rsts) in self.m_expr_chks:
_token_ = self._peek(self.m_expr_chks)
if _token_ == 'MUL':
MUL = self._scan('MUL')
- u_expr = self.u_expr(R)
+ u_expr = self.u_expr()
v = BinaryOp(operator.mul, v, u_expr)
else: # == 'DIV'
DIV = self._scan('DIV')
- u_expr = self.u_expr(R)
+ u_expr = self.u_expr()
v = BinaryOp(operator.div, v, u_expr)
return v
- def u_expr(self, R):
+ def u_expr(self):
_token_ = self._peek(self.u_expr_rsts)
if _token_ == 'SIGN':
SIGN = self._scan('SIGN')
- u_expr = self.u_expr(R)
+ u_expr = self.u_expr()
return UnaryOp(operator.neg, u_expr)
elif _token_ == 'ADD':
ADD = self._scan('ADD')
- u_expr = self.u_expr(R)
+ u_expr = self.u_expr()
return UnaryOp(operator.pos, u_expr)
else: # in self.u_expr_chks
- atom = self.atom(R)
+ atom = self.atom()
return atom
- def atom(self, R):
+ def atom(self):
_token_ = self._peek(self.u_expr_chks)
if _token_ == 'LPAR':
LPAR = self._scan('LPAR')
- expr_lst = self.expr_lst(R)
+ expr_lst = self.expr_lst()
RPAR = self._scan('RPAR')
return expr_lst
elif _token_ == 'ID':
@@ -213,7 +179,7 @@ class Calculator(Parser):
v = ArgspecLiteral([])
LPAR = self._scan('LPAR')
if self._peek(self.atom_rsts) != 'RPAR':
- argspec = self.argspec(R)
+ argspec = self.argspec()
v = argspec
RPAR = self._scan('RPAR')
return CallOp(FNCT, v)
@@ -239,16 +205,16 @@ class Calculator(Parser):
VAR = self._scan('VAR')
return Variable(VAR)
- def argspec(self, R):
- argspec_item = self.argspec_item(R)
+ def argspec(self):
+ argspec_item = self.argspec_item()
v = [argspec_item]
while self._peek(self.argspec_rsts) == 'COMMA':
COMMA = self._scan('COMMA')
- argspec_item = self.argspec_item(R)
+ argspec_item = self.argspec_item()
v.append(argspec_item)
return ArgspecLiteral(v)
- def argspec_item(self, R):
+ def argspec_item(self):
var = None
if self._peek(self.argspec_item_rsts) == 'VAR':
VAR = self._scan('VAR')
@@ -256,23 +222,23 @@ class Calculator(Parser):
self._scan('":"')
var = VAR
else: self._rewind()
- expr_slst = self.expr_slst(R)
+ expr_slst = self.expr_slst()
return (var, expr_slst)
- def expr_lst(self, R):
- expr_slst = self.expr_slst(R)
+ def expr_lst(self):
+ expr_slst = self.expr_slst()
v = [expr_slst]
while self._peek(self.expr_lst_rsts) == 'COMMA':
COMMA = self._scan('COMMA')
- expr_slst = self.expr_slst(R)
+ expr_slst = self.expr_slst()
v.append(expr_slst)
return ListLiteral(v) if len(v) > 1 else v[0]
- def expr_slst(self, R):
- expr = self.expr(R)
+ def expr_slst(self):
+ expr = self.expr()
v = [expr]
while self._peek(self.expr_slst_rsts) not in self.expr_lst_rsts:
- expr = self.expr(R)
+ expr = self.expr()
v.append(expr)
return ListLiteral(v, comma=False) if len(v) > 1 else v[0]
@@ -298,29 +264,5 @@ class Calculator(Parser):
expr_lst_rsts_ = None
- def __init__(self, scanner, library):
- self._library = library
- super(Calculator, self).__init__(scanner)
-
-
### Grammar ends.
################################################################################
-
-P = Calculator(CalculatorScanner())
-
-
-def parse(rule, text, *args):
- P.reset(text)
- return wrap_error_reporter(P, rule, *args)
-
-
-if __name__ == '__main__':
- while True:
- try:
- s = raw_input('>>> ')
- except EOFError:
- break
- if not s.strip():
- break
- print parse('goal', s, None)
- print 'Bye.'