branch : pmacs2
This commit is contained in:
moculus 2007-06-24 15:05:44 +00:00
parent 014b931f16
commit 34b16ad19e
3 changed files with 101 additions and 20 deletions

View File

@ -7,12 +7,12 @@ import util, window2
from point2 import Point
# modes
# TODO: mode_c mode_nasm mode_sql mode_javascript mode_tt
# TODO: mode_sql mode_javascript mode_tt
import mode2
import mode_mini, mode_search, mode_replace, mode_which
import mode_console, mode_consolemini
import mode_blame, mode_diff
import mode_python, mode_perl, mode_xml, mode_nasm, mode_sh
import mode_c, mode_python, mode_perl, mode_xml, mode_nasm, mode_sh
import mode_life, mode_text, mode_mutt
def run(buffers, jump_to_line=None, init_mode=None):
@ -82,7 +82,7 @@ class Application(object):
# initialize our modes
self.modes = {
'blame': mode_blame.Blame,
# 'c': mode_c.C,
'c': mode_c.C,
'console': mode_console.Console,
'consolemini': mode_consolemini.Console,
'diff': mode_diff.Diff,
@ -119,7 +119,7 @@ class Application(object):
'.pl': 'perl',
'.pm': 'perl',
'.t': 'perl',
# '.c': 'c',
'.c': 'c',
'.txt': 'text',
'.s': 'nasm',
'.sh': 'sh',

111
mode_c.py
View File

@ -1,20 +1,106 @@
import sets, sys
import color, mode2
import lex
from lex2 import Grammar, PatternRule, RegionRule
# this might not be complete...
# see http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_3.html#SEC44
import color, mode, lex, lex_c, method, tab_c
class MacroGrammar(Grammar):
rules = [
PatternRule(name=r'continued', pattern=r'.*\\ *$'),
]
class IncludeGrammar(Grammar):
rules = [
PatternRule(name=r'header', pattern=r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'),
]
class C(mode.Fundamental):
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)", grammar=MacroGrammar(), end=r'(?<!\\) *$'),
RegionRule(name=r'include', start=r'#include', grammar=IncludeGrammar(), end=r'$'),
RegionRule(name=r'define', start=r'#define', grammar=Grammar(), end='(?<!\\) *$'),
]
foo = [
{'name': 'constant',
'expr': r'''(?<=#define) +[A-Za-z0-9_]+(?= |\(|\n|$)''',
'action': lex.make_token},
{'name': 'label',
'expr': r"""[a-zA-Z_]+(?=:)""",
'action': lex.make_token},
{'name': "c++ comment",
'expr': r'//.*(?:\n|$)',
'action': lex.make_token},
{'name': "c comment",
'expr': r"/\*(?:.|\n)*?(?:\*/|$)",
'action' : lex.make_token},
{'name': 'control',
'expr': r"(?:break|case|continue|default|do|else|for|goto|if|return|switch|while)(?![a-zA-Z_])",
'action': lex.make_token},
{'name': 'keyword',
'expr': 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_])",
'action': lex.make_token},
{'name': 'builtin',
'expr': r"(?:NULL|TRUE|FALSE)",
'action': lex.make_token},
{'name': "identifier",
'expr': r"[a-zA-Z_][a-zA-Z0-9_]*",
'action': lex.make_token},
{'name': "unary operator",
'expr': r"""\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=""",
'action': lex.make_token},
{'name': "operator",
'expr': r"""\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%""",
'action': lex.make_token},
# this is sketchy as hell
{'name': "delimiter",
'expr': r"""->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?""",
'action': lex.make_token},
{'name': "integer",
'expr': r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?",
'action': lex.make_token},
{'name': "float",
'expr': r"""[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+""",
'action': lex.make_token},
{'name': "string1",
'expr': r'"(?:\\.|[^"])*(?:"|.?$)',
'action': lex.make_token},
# Doesn't handle octal . . (yeah it does..heh...ughhh)
{'name': "char",
'expr': r"'(?:\\[^']+|[^'])(?:'|.?$)",
'action': lex.make_token},
{'name': "default",
'expr': r'\\.|.|\n',
'action': lex.silent}
]
class C(mode2.Fundamental):
#tabbercls = CTabber
grammar = CGrammar()
opentoken = 'delimiter'
opentags = {'(': ')', '[': ']', '{': '}'}
closetoken = 'delimiter'
closetags = {')': '(', ']': '[', '}': '{'}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.tag_matching = True
self.grammar = lex_c.CGrammar()
self.lexer = lex.Lexer(self.grammar)
mode2.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.default_color = color.build('default', 'default')
self.colors = {
'control': color.build('blue', 'default', 'bold'),
'keyword': color.build('cyan', 'default', 'bold'),
@ -34,8 +120,5 @@ class C(mode.Fundamental):
'float': color.build('green', 'default'),
'bizzaro': color.build('magenta', 'green'),
}
self.tabber = tab_c.CTabber(self)
def name(self):
return "C"

View File

@ -184,8 +184,6 @@ class Perl(mode2.Fundamental):
self.add_bindings('close-bracket', (']'))
self.add_bindings('close-brace', ('}'))
self.default_color = color.build('default', 'default')
self.colors = {
# basic stuff
'escaped': color.build('magenta', 'default'),