more c mode improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-09-26 14:22:19 +00:00
parent 691ada2f4b
commit 832448bbea
2 changed files with 34 additions and 6 deletions

View File

@ -73,6 +73,22 @@ class DumpTokens(Method):
output = "\n".join(lines)
w.application.data_buffer("token-dump", output, switch_to=True)
class DumpAggregateTokenData(Method):
'''Dump all lexical tokens into an aggregated format'''
def _execute(self, w, **vargs):
name = w.mode.name()
lines = []
if modename in w.buffer.highlights:
tokens = w.buffer.highlights[name].tokens
for group in tokens:
for token in group:
s1 = token.name
s2 = token.fqname()
n = len(token.string)
lines.append('%-s %-s %3d %-s' % (s1, s2, n, token.string))
output = "\n".join(lines)
w.application.data_buffer("token-dump", output, switch_to=True)
class GetToken(Method):
'''View type and data of the "current" token'''
def _execute(self, w, **vargs):

View File

@ -8,10 +8,14 @@ from mode.python import StringGrammar
# see http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_3.html#SEC44
class MacroGrammar(Grammar):
rules = [
RegionRule(r'comment', r'/\*', Grammar, r'\*/'),
PatternRule(r'comment', r'//.*$'),
PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=|\^=|>>=|<<=|\*\*=|\|="),
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
PatternRule(r"identifier", r"[a-zA-Z_][a-zA-Z0-9_]*"),
PatternRule(r"integer", r"-?(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"float", r"-?(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)"),
RegionRule(r'string', '"', StringGrammar, '"'),
@ -37,7 +41,7 @@ class CGrammar(Grammar):
PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*(?! *[\(:])"),
RegionRule(r'macro', r'#(?:assert|cpu|define|elif|else|endif|error|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])', MacroGrammar, r'\n$'),
RegionRule(r'macro', r'# *(?:assert|cpu|define|elif|else|endif|error|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])', MacroGrammar, r'\n$'),
RegionRule(r'comment', r'/\*', Grammar, r'\*/'),
PatternRule(r'comment', r'//.*$'),
@ -52,8 +56,14 @@ class CGrammar(Grammar):
RegionRule(r'macrocomment', r'#if +(?:0|NULL|FALSE)', Grammar, r'#endif'),
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternRule(r'include', r'#include(?!=[a-zA-Z0-9_])'),
PatternRule(r'header', r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'),
PatternGroupRule(r'includegrp', r'macro.start', r'# *include', r'spaces',
r' +', r'header', r'< *[-A-Za-z/0-9_.]+ *>|" *[-A-Za-z/0-9_.]+ *"'),
#PatternGroupRule(r'ifndefgrp', r'macro.start', r'# *ifndef', r'spaces',
# r' +', r'header', r'< *[-A-Za-z/0-9_.]+ *>|" *[-A-Za-z/0-9_.]+ *"'),
#PatternRule(r'include', r'#include(?!=[a-zA-Z0-9_])'),
#PatternRule(r'header', r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'),
#PatternRule(r'enumname', r'(?<=enum ) *[a-zA-Z_][a-zA-Z0-9_]*'),
#PatternRule(r'structname', r'(?<=struct ) *[a-zA-Z_][a-zA-Z0-9_]*'),
@ -227,6 +237,8 @@ class C(mode.Fundamental):
'macro.null': ('magenta', 'default', 'bold'),
'macro.continued': ('red', 'default', 'bold'),
'macro.delimiter': ('default', 'default', 'bold'),
'macro.identifier': ('yellow', 'default', 'bold'),
'macro.bareword': ('yellow', 'default', 'bold'),
'macro.integer': ('green', 'default', 'bold'),
'macro.float': ('green', 'default', 'bold'),
'macro.char': ('green', 'default', 'bold'),