Exemplo n.º 1
0
 def next_literal_mode(self):
     # "literal" mode, i.e. outside "<?php ?>" tags: generates
     # one B_LITERAL_BLOCK until the next opening "<?php" tag
     self.mode = MODE_PHPCODE
     source = self.source
     index = self.startindex
     assert index >= 0
     tagindex = source.find('<?', index)
     if tagindex == -1:
         tagindex = len(source)
     assert tagindex >= 0
     startindex = self.startindex
     assert startindex >= 0
     block_of_text = source[startindex:tagindex]  # may be empty
     tok = Token('B_LITERAL_BLOCK', block_of_text, self.startlineno)
     self.startlineno += block_of_text.count('\n')
     if source[tagindex:tagindex + 5].lower() == '<?php':
         pos = tagindex + 5
     elif source[tagindex:tagindex + 3] == '<?=':
         pos = tagindex + 3
         self.mode = MODE_EQUALSIGN
     else:
         pos = tagindex + 2
     self.lexer.input(self.source, pos, self.startlineno)
     return tok
Exemplo n.º 2
0
 def end_current_block(self, tok, endpos):
     # a "?>" marker that ends the current block of code
     # generates a ";" token followed by a B_LITERAL_BLOCK
     self.startlineno = tok.getsourcepos()
     self.startindex = endpos
     self.mode = MODE_LITERAL
     if (self.startindex < len(self.source)
             and self.source[self.startindex] == '\n'):
         self.startlineno += 1  # consume \n if immediately following
         self.startindex += 1
     return Token(";", ";", tok.getsourcepos())
Exemplo n.º 3
0
 def token(self):
     if self.pos >= len(self.buf):
         return None
     for rule, token_type in self.rules:
         m = rule.match(self.buf, pos=self.pos)
         if m:
             end = m.end()
             assert end >= 0
             val = self.buf[self.pos:end]
             tok = Token(token_type, val, SourcePosition(self.pos, self.lineno, 0))
             if token_type == "END_OF_LINE":
                 self.lineno += 1
             self.pos = end
             return tok
     raise IniLexerError(self.lineno)
Exemplo n.º 4
0
 def whitespace_empty(self, p):
     return Token('H_WHITESPACE', '', SourcePosition(0, 0, 0))
Exemplo n.º 5
0
 def next_equal_sign(self):
     self.mode = MODE_PHPCODE
     return Token("T_ECHO", "echo", self.startlineno)