bugfixes, etc

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-11 08:55:54 +00:00
parent 691f454dbe
commit 9258c8e0b4
4 changed files with 45 additions and 39 deletions

View File

@ -1,43 +1,43 @@
import color, mode2
from lex2 import Grammar, PatternRule, RegionRule
from mode_python import StringGrammar
# this might not be complete...
# see http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_3.html#SEC44
class MacroGrammar(Grammar):
rules = [
PatternRule(name='continued', pattern=r'.*\\ *$'),
]
class StringGrammar(Grammar):
rules = [
PatternRule(name=r'escaped', pattern=r'\\.'),
PatternRule(name='name', pattern=r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(name='continued', pattern=r'\\ *$'),
RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'),
PatternRule(name=r'char', pattern=r"'.'|'\\.'|'\\[0-7]{3}'")
]
class CGrammar(Grammar):
rules = [
#PatternRule(name=r'macro1', pattern=r'#(?:define|import|include|undef)(?!=[a-zA-Z0-9_])'),
RegionRule(
name=r'macro2',
start=r"#(?:assert|cpu|elif|else|error|endif|ident|ifdef|ifndef|if|include_next|line|machine|pragma|pragma_once|system|unassert|warning)(?!=[a-zA-Z0-9_])",
grammar=Grammar(),
end=r'(?<!\\) *$',
),
PatternRule(name=r'include', pattern=r'#include(?!=[a-zA-Z0-9_])'),
PatternRule(name=r'header', pattern=r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'),
PatternRule(name=r'macro', pattern=r'#(?:endif)'),
RegionRule(
name=r'macro',
start=r'#(?:assert|cpu|define|elif|else|error|endif|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])',
start=r'#(?:assert|cpu|define|elif|else|error|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])',
grammar=MacroGrammar(),
end=r'(?:.*[^\\])?$',
end=r'[^\\ ] *$',
),
PatternRule(name=r'label', pattern=r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
RegionRule(name=r'comment1', start='/\*', grammar=Grammar(), end='\*/'),
PatternRule(name=r'comment2', pattern=r'//.*$'),
PatternRule(name=r'control', pattern=r"(?:break|case|continue|default|do|else|for|goto|if|return|switch|while)(?![a-zA-Z_])"),
PatternRule(name=r'keyword', pattern=r"(?:auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)(?![a-zA-z_])"),
PatternRule(name=r'keyword', pattern=r"(?:auto|break|case|char|const|continue|default|double|do|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)(?![a-zA-z_])"),
PatternRule(r'structname', r'(?<=struct ) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r'enumname', r'(?<=enum ) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
PatternRule(name=r'builtin', pattern=r"(?:NULL|TRUE|FALSE)"),
PatternRule(name=r'identifier', pattern=r"[a-zA-Z_][a-zA-Z0-9_]*"),
PatternRule(name=r"unop", pattern=r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(name=r'binop', pattern=r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
# this is sketchy as hell
PatternRule(name=r"delimiter", pattern=r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
PatternRule(name=r"integer", pattern=r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
@ -59,34 +59,45 @@ class C(mode2.Fundamental):
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.colors = {
'label': color.build('magenta', 'default'),
'include': color.build('blue', 'default'),
'header': color.build('green', 'default'),
'macro.start': color.build('blue', 'default', 'bold'),
'macro.continued': color.build('default', 'default', 'bold'),
'macro.end': color.build('default', 'default', 'bold'),
'macro.start': color.build('blue', 'default'),
'macro.name': color.build('yellow', 'default'),
'macro.null': color.build('blue', 'default'),
'macro.continued': color.build('red', 'default'),
'macro.char': color.build('green', 'default'),
'macro.string.start': color.build('green', 'default'),
'macro.string.escaped': color.build('magenta', 'default'),
'macro.string.octal': color.build('magenta', 'default'),
'macro.string.null': color.build('green', 'default'),
'macro.string.end': color.build('green', 'default'),
'macro.end': color.build('blue', 'default'),
'keyword': color.build('cyan', 'default'),
'control': color.build('blue', 'default', 'bold'),
'keyword': color.build('cyan', 'default', 'bold'),
'macro1': color.build('blue', 'default', 'bold'),
'macro2': color.build('blue', 'default', 'bold'),
'constant': color.build('magenta', 'default', 'bold'),
'header': color.build('green', 'default', 'bold'),
'label': color.build('magenta', 'default', 'bold'),
'char': color.build('green', 'default'),
'builtin': color.build('magenta', 'default', 'bold'),
'comment1.start': color.build('red', 'default'),
'comment1.end': color.build('red', 'default'),
'comment1.null': color.build('red', 'default'),
'comment2': color.build('red', 'default'),
'function': color.build('blue', 'default'),
'builtin': color.build('magenta', 'default'),
'structname': color.build('yellow', 'default'),
'enumname': color.build('yellow', 'default'),
'char': color.build('green', 'default'),
'string.start': color.build('green', 'default'),
'string.octal': color.build('green', 'default'),
'string.escaped': color.build('green', 'default'),
'string.null': color.build('green', 'default'),
'string.end': color.build('green', 'default'),
'macro comment': color.build('red', 'default'),
'function name': color.build('blue', 'default'),
'integer': color.build('green', 'default'),
'float': color.build('green', 'default'),
'bizzaro': color.build('magenta', 'green'),
}
def name(self):

View File

@ -1,12 +1,7 @@
import color, mode2
from lex2 import Grammar, PatternRule, RegionRule
from point2 import Point
class StringGrammar(Grammar):
rules = [
PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'),
PatternRule(name=r'escaped', pattern=r'\\.'),
]
from mode_python import StringGrammar
class JavascriptGrammar(Grammar):
rules = [

View File

@ -1,7 +1,7 @@
import re
# meta regexes
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\\])')
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\"\'\\,])')
# shell
shell_command = re.compile(r'^[^ ]+')

View File

@ -21,7 +21,7 @@ def find_ranges(r, w, start=None, end=None):
else:
(x, y) = start.xy()
if end is None:
(x2, y2) = (len(w.buffer.lines[-1]) - 1, len(w.buffer.lines) - 1)
(x2, y2) = (len(w.buffer.lines[-1]), len(w.buffer.lines) - 1)
else:
(x2, y2) = end.xy()
@ -30,7 +30,7 @@ def find_ranges(r, w, start=None, end=None):
if y == y2:
limit = x2
else:
limit = len(w.buffer.lines[y]) - 1
limit = len(w.buffer.lines[y])
for m in r.finditer(w.buffer.lines[y], x, limit):
if len(m.group(0)) == 0:
raise IllegalPatternError, "zero-width match found"