]>
git.saurik.com Git - cycript.git/blob - Parser.py
5 lines
= sys
. stdin
. read (). rstrip ( ' \n ' ). split ( ' \n ' )
8 name
= line
[ 0 ]. replace ( '&' , 'Ampersand' ). replace ( '^' , 'Carrot' ). replace ( '=' , 'Equal' ). replace ( '!' , 'Exclamation' ). replace ( '-' , 'Hyphen' ). replace ( '<' , 'Left' ). replace ( '%' , 'Percent' ). replace ( '.' , 'Period' ). replace ( '|' , 'Pipe' ). replace ( '+' , 'Plus' ). replace ( '>' , 'Right' ). replace ( '/' , 'Slash' ). replace ( '*' , 'Star' ). replace ( '~' , 'Tilde' )
10 word
= text
[ 0 ]. isalpha ()
11 prefix
= None if line
[ 1 ] == '-' else line
[ 1 ]
12 assign
= None if len ( line
) < 3 or line
[ 2 ] != 'A' else '' if len ( line
) < 4 else line
[ 3 ]
13 infix
= None if len ( line
) < 3 or line
[ 2 ] != 'R' else line
[ 3 ]
14 precedence
= line
[ 4 ] if infix
!= None and len ( line
) > 4 else None
15 postfix
= infix
if infix
!= None and precedence
== None else None
18 return name
, text
, word
, prefix
, assign
, infix
, precedence
, postfix
20 def express ( expression
, type , args
, call
):
21 print 'struct CYExpression %(expression)s :' % locals ()
22 print ' CYExpression %(type)s ' % locals ()
24 print ' CYExpression %(expression)s ( %(args)s ) :' % locals ()
25 print ' CYExpression %(type)s ( %(call)s )' % locals ()
33 name
, text
, word
, prefix
, assign
, infix
, precedence
, postfix
= data ( line
)
35 print 'struct CYToken %(name)s :' % locals ()
37 print ' CYTokenPrefix,'
39 print ' CYTokenInfix,'
41 print ' CYTokenPostfix,'
43 print ' CYTokenAssignment,'
46 print ' virtual CYToken'
48 print ' virtual const char *Text() const {'
49 print ' return " %(text)s ";' % locals ()
51 if precedence
!= None or prefix
!= None or assign
!= None or infix
!= None :
53 if precedence
!= None :
54 print ' virtual unsigned Precedence() const {'
55 print ' return %(precedence)s ;' % locals ()
59 print ' virtual CYExpression *PrefixExpression(apr_pool_t *pool, CYExpression *rhs) const;'
61 print ' virtual CYExpression *InfixExpression(apr_pool_t *pool, CYExpression *lhs, CYExpression *rhs) const;'
63 print ' virtual CYExpression *PostfixExpression(apr_pool_t *pool, CYExpression *lhs) const;'
65 print ' virtual CYExpression *AssignmentExpression(apr_pool_t *pool, CYExpression *lhs, CYExpression *rhs) const;'
69 express ( prefix
, 'Prefix' , 'CYExpression *rhs' , 'rhs' )
71 express ( infix
, 'Infix' , 'CYExpression *lhs, CYExpression *rhs' , 'lhs, rhs' )
73 express ( postfix
, 'Postfix' , 'CYExpression *lhs' , 'lhs' )
75 express ( 'Assign' + assign
, 'Assignment' , 'CYExpression *lhs, CYExpression *rhs' , 'lhs, rhs' )
79 name
, text
, word
, prefix
, assign
, infix
, precedence
, postfix
= data ( line
)
82 print 'CYExpression *CYToken %(name)s ::PrefixExpression(apr_pool_t *pool, CYExpression *rhs) const {' % locals ()
83 print ' return new(pool) CYExpression %(prefix)s (rhs);' % locals ()
87 print 'CYExpression *CYToken %(name)s ::InfixExpression(apr_pool_t *pool, CYExpression *lhs, CYExpression *rhs) const {' % locals ()
88 print ' return new(pool) CYExpression %(infix)s (lhs, rhs);' % locals ()
92 print 'CYExpression *CYToken %(name)s ::PostfixExpression(apr_pool_t *pool, CYExpression *rhs) const {' % locals ()
93 print ' return new(pool) CYExpression %(postfix)s (rhs);' % locals ()
97 print 'CYExpression *CYToken %(name)s ::AssignmentExpression(apr_pool_t *pool, CYExpression *lhs, CYExpression *rhs) const {' % locals ()
98 print ' return new(pool) CYExpressionAssign %(assign)s (lhs, rhs);' % locals ()