Ejemplo n.º 1
0
def _props_expand(start, end, context):
    
    tt = context[ENVVAR_TOKEN_TYPE]
    
    start_ = connector()
    end_ = connector()
    hlp = connector()
    prop_end = connector()       
    
    start\
    .connect(tn(BRACE_OPEN))\
    .connect(start_)
    
    is_flag = True
    
    if tt == KEYWORD:
        start_.connect(tn(CASE_SENSITIVE, 'case-sensitive')).connect(hlp)
    elif tt == WORD:
        is_flag = False
        start_\
        .connect(tn(FILTER_CB, 'filter-callback'))\
        .connect(tn(COLON))\
        .connect(tn(ID, 'filter-callback-name'))\
        .connect(prop_end)
    elif tt == PREFIX:
        start_.connect(tn(ESCAPE, 'escape')).connect(hlp)
    elif tt == POSTFIX:
        start_.connect(tn(ESCAPE, 'escape')).connect(hlp)
    elif tt == SEPARATOR:
        start_.connect(tn(IS_PATTERN, 'pattern')).connect(hlp)
        start_.connect(tn(WS_ALLOWED, 'ws-allowed')).connect(hlp)
        start_.connect(tn(ESCAPE, 'escape')).connect(hlp)
    else:
        raise Exception("Unknown property target")
    
    if is_flag:
    
        hlp\
        .connect(tn(COLON))\
        .connect(tn(TRUE, 'true'))\
        .connect(prop_end)
    
        hlp\
        .connect(tn(COLON))\
        .connect(tn(FALSE, 'false'))\
        .connect(prop_end)
    
    prop_end.connect(tn(COMMA)).connect(start_)
    prop_end.connect(end_)
        
    end_\
    .connect(tn(BRACE_CLOSE))\
    .connect(end)
Ejemplo n.º 2
0
 def expand(self, start, end, context):
     
     end_ = connector()
     
     start\
     .connect(tn(self._token_type))\
     .connect(tn(TOKEN_ID, "id"))\
     .connect(end_)
     
     if not self._token_type in [LITERAL, TEXT_BLOCK]:
         end_ = end_.connect(tn(TOKEN_VALUE, "value"))
     
     if self._token_type in [KEYWORD, WORD, PREFIX, POSTFIX, SEPARATOR]:
         end_.connect(_PropsRule('properties')).connect(end)
     
     end_.connect(tn(SEMICOLON)).connect(end)