예제 #1
0
def p_stmt(p):
    '''
    stmt : fragment NEWLINE
         | fragment
         | NEWLINE         
         | block
    '''
    p[0] = Node(kind='stmt', childs=p)
예제 #2
0
def p_block_keyword(p):
    '''
    block_keyword : CLASS
                    | DEF
                    | IF
                    | ELIF
                    | ELSE
                    | TRY
                    | EXCEPT
                    | FINALLY
                    | WITH
                    | WHILE
                    | FOR
    '''
    p[0] = Node(kind='keyword', childs=p)
예제 #3
0
def p_fragment(p):
    '''
    fragment : fragment LBRACE
         | fragment RBRACE
         | fragment STRING_END
         | fragment STRING_CONTINUE
         | fragment STRING
         | fragment STRING_START_TRIPLE
         | fragment WS 
         | fragment STRING_START_SINGLE
         | fragment NUMBER
         | fragment NAME
         | fragment LPAR
         | fragment RPAR
         | fragment OPERATOR
         | fragment LSQB
         | fragment RSQB
         | fragment COLON
         | fragment block_keyword
         | fragment PERIOD
         | fragment RANGE
         | block_keyword
         | LBRACE
         | RBRACE
         | STRING_END
         | STRING_CONTINUE
         | STRING
         | STRING_START_TRIPLE
         | WS 
         | STRING_START_SINGLE
         | NUMBER
         | NAME
         | LPAR
         | RPAR
         | LSQB
         | RSQB
         | COLON
         | OPERATOR
         | COMMENT
         | RANGE
    '''
    p[0] = Node(kind='fragment', childs=p)
예제 #4
0
def p_suite(p):
    '''
    suite : stmt
          | suite stmt 
    '''
    p[0] = Node(kind='suite', childs=p)
예제 #5
0
def p_empty_block(p):
    '''
    block : block_keyword fragment COLON NEWLINE 
    '''
    p[0] = Node(kind='block', childs=p)
예제 #6
0
def p_inline_block(p):
    '''
    block : block_keyword fragment COLON suite 
    '''
    p[0] = Node(kind='block', childs=p)
예제 #7
0
def p_block(p):
    '''
    block : block_keyword fragment COLON NEWLINE INDENT suite DEDENT
    '''
    p[0] = Node(kind='block', childs=p)
예제 #8
0
def p_file_input(p):
    '''
    file_input : suite ENDMARKER
    '''
    p[0] = Node(kind='file_input', childs=p)