pmacs3/mode/php.py

70 lines
4.0 KiB
Python
Raw Permalink Normal View History

from mode import Fundamental
2008-07-14 19:24:26 -04:00
from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar
2009-02-15 12:06:35 -05:00
class PHPGrammar(Grammar):
2008-07-14 19:24:26 -04:00
rules = [
#PatternRule(r'import', r'(?<=import ) *[a-zA-Z0-9_.*]+'),
#PatternRule(r'package', r'(?<=package ) *[a-zA-Z0-9_.*]+'),
RegionRule(r'comment', r'/\*', Grammar, '\*/'),
PatternRule(r'comment', r'//.*$'),
PatternRule(r'comment', r'#.*$'),
PatternRule(r'php_builtin_vars', r'GATEWAY_INTERFACE|SERVER_NAME|SERVER_SOFTWARE|SERVER_PROTOCOL|REQUEST_METHOD|QUERY_STRIN|G|DOCUMENT_ROOT|HTTP_ACCEPT|HTTP_ACCEPT_CHARSET|HTTP_ENCODING|HTTP_ACCEPT_LANGUAGE|HTTP_CONNECTION|HTTP_HOST|HTTP_REFERER|HTTP_USER_AGENT|REMOTE_ADDR|REMOTE_PORT|SCRIPT_FILENAME|SERVER_ADMIN|SERVER_PORT|SERVER_SIGNATURE|PATH_TRANSLATED|SCRIPT_NAME|REQUEST_URI'),
PatternRule(r'php_builtin_vars', r'GLOBALS|PHP_ERRMSG|PHP_SELF|HTTP_GET_VARS|HTTP_POST_VARS|HTTP_COOKIE_VARS|HTTP_POST_FILES|HTTP_ENV_VARS|HTTP_SERVER_VARS|HTTP_SESSION_VARS|HTTP_RAW_POST_DATA|HTTP_STATE_VARS|_GET|_POST|_COOKIE|_FILES|_SERVER|_ENV|_SERVER|_REQUEST|_SESSION'),
PatternRule(r'php_constants', r'__LINE__|__FILE__|__FUNCTION__|__METHOD__|__CLASS__'),
PatternRule(r'php_constants', r'PHP_VERSION|PHP_OS|DEFAULT_INCLUDE_PATH|PEAR_INSTALL_DIR|PEAR_EXTENSION_DIR|PHP_EXTENSION_DIR|PHP_BINDIR|PHP_LIBDIR|PHP_DATADIR|PHP_SYSCONFDIR|PHP_LOCALSTATEDIR|PHP_CONFIG_FILE_PATH|PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CONT|PHP_OUTPUT_HANDLER_END|E_ERROR|E_WARNING|E_PARSE|E_NOTICE|E_CORE_ERROR|E_CORE_WARNING|E_COMPILE_ERROR|E_COMPILE_WARNING|E_USER_ERROR|E_USER_WARNING|E_USER_NOTICE|E_ALL'),
PatternRule(r'keyword', r"(?:abstract|assert|boolean|break|byte|case|catch|char|class|continue|default|double|do|else|extends|finally|final|float|for|if|implements|import|instanceof|interface|int|long|native|new|package|private|protected|public|return|short|static|switch|super|synchronized|threadsafe|throws|throw|transient|try|void|while)(?![a-zA-Z_])"),
2009-02-15 12:06:35 -05:00
PatternRule(r'php_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
2008-07-14 19:24:26 -04:00
2009-02-15 12:06:35 -05:00
PatternRule(r'php_builtin', r"(?:null|true|false|this)"),
2008-07-14 19:24:26 -04:00
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
2009-02-15 12:06:35 -05:00
PatternRule(r"php_integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"php_float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
2008-07-14 19:24:26 -04:00
RegionRule(r'string', '"', StringGrammar, '"'),
2009-02-15 12:06:35 -05:00
PatternRule(r'php_char', r"'.'|'\\.'|'\\[0-7]{3}'"),
2008-07-14 19:24:26 -04:00
PatternRule(r"eol", r"\n$"),
]
class PHP(Fundamental):
name = 'PHP'
2009-02-15 12:06:35 -05:00
extensions = ['.php']
#tabbercls = JavaTabber
grammar = PHPGrammar
commentc = '#'
2008-07-14 19:24:26 -04:00
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'doccomment.start': ('red', 'default', 'bold'),
'doccomment.end': ('red', 'default', 'bold'),
'doccomment.null': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'),
'php_label': ('magenta', 'default', 'bold'),
'php_builtin': ('magenta', 'default', 'bold'),
'php_char': ('green', 'default', 'bold'),
'php_integer': ('green', 'default', 'bold'),
'php_float': ('green', 'default', 'bold'),
}
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
2008-07-14 19:24:26 -04:00
}
def __init__(self, w):
Fundamental.__init__(self, w)
2008-07-14 19:24:26 -04:00
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
2009-02-15 12:06:35 -05:00
install = PHP.install