Easy Extend
|
|
||
Author: Kay Schluehr Date: 2008 - 03 - 01 Version: For EasyExtend 3.0 |
repeat_stmt |
::= | 'repeat' ':'
suite 'until' ':' (NEWLINE INDENT test NEWLINE DEDENT | test NEWLINE ) |
repeat: SUITE until: TEST |
==> |
while
1: SUITE if TEST: break |
gal>
x = 0 gal> repeat: .... x+=1 .... until: .... x==10 .... gal> x 10 |
gal>
x = 0 gal> repeat: .... x+=1 .... until: x==10 .... gal> x 10 |
var = dictionary.get(key) if var: SUITE_1 else: SUITE_2 |
if dictionary.get(key) as var: SUITE_1 else: SUITE_2 |
on_stmt |
::= | 'on' NAME '='
test ':' suite ['else' ':' suite] |
on NAME = test: SUITE1 else: SUITE2 |
==> |
NAME = test if NAME: SUITE else: SUITE |
gal>
on n0 = find_node(tree, symbol.stmt): .... on n1 = find_node(n0, symbol.flow_stmt): .... print n1 |
d
= {2:5, 3:9} x = 0 repeat: on m = d.get(x): x = m break x+=1 until: x == 3 assert x == 5 |
if language == Python_2_4: BLOCK |
if language &
(Python_2_4_2|Python_2_5): BLOCK |
if language <=
Python_2_4_2: BLOCK |
if language <=
Python_2_4_2: BLOCK |
gal>
A = Chainlet() gal> B = A() gal> B<A # A is parent of B True gal> C = A() gal> C<A # A is parent of C True gal> C<=B # The pair (B,C) is not element of the parental order relationship False gal> B<=C False |
chainlet) |
chainlet) |
*chainlets) |
gal>
PY = Chainlet() gal> PY_1X = PY() gal> PY_24 = PY() gal> PY_25 = PY_24() gal> PY_25.select(PY, PY_1X) PY gal> PY_25.select(PY,PY_24) PY_24 gal> PY_24.select(PY_25) # returns None gal> |
chainlet) |
chainlet) |
def get_charge(days_rented): result = 0 price_code = get_price_code() if price_code == MOVIE.REGULAR: result+=2 if days_rented>2: result+= (days_rented-2)*1.5 elif price_code == MOVIE.NEW_RELEASE: result+= days_rented*3 elif price_code == MOVIE.CHILDRENS: result+=1.5 if days_rented>3: result+= (days_rented-3)*1.5 return result |
def get_charge(days_rented,
start, barrier, factor = 1.5): result = start if days_rented>barrier: result+=(days_rented-barrier)*factor return result |
def get_charge(days_rented,
start, barrier, factor = 1.5): result = start if barrier: if days_rented>barrier: result+=(days_rented-barrier)*factor else: result+=2*factor return result |
|
code =
price_code.select(MOVIE.REGULAR, MOVIE.CHILDRENS, MOVIE.NEW_RELEASE)
====> code = price_code.select(MOVIE.REGULAR, MOVIE.CHILDRENS|MOVIE.STUDENTS, MOVIE.NEW_RELEASE) |
STUDENTS = CHILDREN() |
REDUCTION =
PRICE_CODE() STUDENTS = REDUCTION() CHILDREN = REDUCTION() PUPILS = REDUCTION() PENSIONEERS = REDUCTION() |
code =
price_code.select(MOVIE.REDUCED)
code = price_code.select(MOVIE.REDUCED, MOVIE.PUPILS|MOVIE.STUDENTS) code = price_code.select(MOVIE.REDUCED, MOVIE.CHILDREN, MOVIE.PENSIONEERS) ... |
switch_stmt |
::= | 'switch' expr
':' NEWLINE INDENT case_stmt DEDENT ['else' ':' suite] |
case_stmt | ::= | 'case' expr ':' suite ('case' expr ':' suite)* |
switch
EXPR: case EXPR1: SUITE1 case EXPR2: SUITE2 else: SUITE3 |
==> |
if
isChainlet(EXPR): SELECT = EXPR.select(EXPR1,EXPR2) else: SELECT = EXPR if SELECT == EXPR1: SUITE1 elif SELECT == EXPR2: SUITE2 else: SUITE3 |
switch x: case x in range(100): SUITE .... |
gal>
x = 0; y = 5 gal> switch x: .... case y-4: .... print 1 .... case y-5: .... print 2 .... else: .... print 3 2 gal> |
switch
code: case MOVIE.REGULAR: charge = get_charge(days_rented, 2, 2) case MOVIE.REDUCED: charge = get_charge(days_rented, 1.5, 3) case MOVIE.NEW_RELEASE: charge = get_charge(days_rented, 0, 0, 3) else: raise ValueError, "Unknown price code %s"%code |
thunk_stmt |
::= | small_stmt ':'
suite
|
class
A(object): x = property: def fget(self): return self._x def fset(self, val): self._x = val |
def
foo(x): print x return 1 + %fn(): if x<0: return x**2 -1 else: return x**2 +1 |
thunk_stmtGallery_3.0 |
::= | NAME '=' NAME
':' suite
|
NAME_1
= NAME_2: SUITE |
==> |
def
tunk(): SUITE return locals() NAME_1 = NAME_2(**thunk()) del thunk |
gal>
127.0.0.1 <IPv4:127.0.0.1> gal> 127.0.0.1[0] 127 gal> 127.0.0.1[2:] (0,1) |
IPv4Address Triple |
::= ::= |
Triple '.' Triple
'.' Triple '.' Triple
A_DIGIT [A_DIGIT] [A_DIGIT] |