def get_tokens_unprocessed(self, text):
phplexer = PhpLexer(**self.options)
curcode = ''
insertions = [] for match in line_re.finditer(text):
line = match.group() if line.startswith('>>> ') or line.startswith('... '):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:4])]))
curcode += line[4:] elif line.rstrip() == '...':
insertions.append((len(curcode),
[(0, Generic.Prompt, '...')]))
curcode += line[3:] else: if curcode: yieldfrom do_insertions(
insertions, phplexer.get_tokens_unprocessed(curcode))
curcode = ''
insertions = [] yield match.start(), Generic.Output, line if curcode: yieldfrom do_insertions(insertions,
phplexer.get_tokens_unprocessed(curcode))
class PhpLexer(RegexLexer): """ For PHP source code. For PHP embedded in HTML, use the `HtmlPhpLexer`.
Additional options accepted:
`startinline` If given and ``True`` the lexer starts highlighting with
php code (i.e.: no starting ``<?php`` required). The default is ``False``.
`funcnamehighlighting` If given and ``True``, highlight builtin function names
(default: ``True``).
`disabledmodules` If given, must be a list of module names whose function names
should not be highlighted. By default all modules are highlighted except the special ``'unknown'`` module that includes functions
that are known to php but are undocumented.
To get a list of allowed modules have a look into the
`_php_builtins` module:
# Note that a backslash is included, PHP uses a backslash as a namespace # separator.
_ident_inner = r'(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*' # But not inside strings.
_ident_nons = r'(?:[_a-z]|[^\x00-\x7f])(?:\w|[^\x00-\x7f])*'
# private option argument for the lexer itself if'_startinline'in options:
self.startinline = options.pop('_startinline')
# collect activated functions in a set
self._functions = set() if self.funcnamehighlighting: from pygments.lexers._php_builtins import MODULES for key, value in MODULES.items(): if key notin self.disabledmodules:
self._functions.update(value)
RegexLexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
stack = ['root'] if self.startinline:
stack.append('php') for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text, stack): if token is Name.Other: if value in self._functions: yield index, Name.Builtin, value continue yield index, token, value
def analyse_text(text): if shebang_matches(text, r'php'): returnTrue
rv = 0.0 if re.search(r'<\?(?!xml)', text):
rv += 0.3 return rv
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.