diff --git a/mode_c.py b/mode_c.py index e311eb0..f0d9d9a 100644 --- a/mode_c.py +++ b/mode_c.py @@ -9,7 +9,15 @@ class MacroGrammar(Grammar): rules = [ PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('continued', r'\\ *$'), - RegionRule(r'string', '"', StringGrammar(), '"'), + RegionRule(r'string', '"', StringGrammar, '"'), + PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'") + ] + +class MacroGrammar(Grammar): + rules = [ + PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'), + PatternRule('continued', r'\\ *$'), + RegionRule(r'string', '"', StringGrammar, '"'), PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'") ] @@ -17,14 +25,15 @@ class CGrammar(Grammar): rules = [ 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'macro', r'#(?:endif)'), - RegionRule(r'macro', 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_])', MacroGrammar(), r'[^\\ ] *$'), + PatternRule(r'macro', r'#(?:else|endif)'), + RegionRule(r'macro', r'#(?:assert|cpu|define|elif|error|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])', MacroGrammar(), r'[^\\ ] *$'), - PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'), + RegionRule(r'macrocomment', r'#if +(?:0|NULL|FALSE)', Grammar, r'#endif'), RegionRule(r'comment1', '/\*', Grammar(), '\*/'), PatternRule(r'comment2', r'//.*$'), - PatternRule(r'keyword', 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'keyword', 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'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'), 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_]*(?= *\()'), @@ -56,13 +65,21 @@ class C(mode2.Fundamental): self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) self.colors = { - 'label': color.build('magenta', 'default'), + 'macrocomment.start': color.build('red', 'default'), + 'macrocomment.null': color.build('red', 'default'), + 'macrocomment.end': color.build('red', 'default'), + 'comment1.start': color.build('red', 'default'), + 'comment1.end': color.build('red', 'default'), + 'comment1.null': color.build('red', 'default'), + 'comment2': color.build('red', 'default'), + 'include': color.build('blue', 'default'), 'header': color.build('green', 'default'), + 'macro': color.build('blue', 'default'), 'macro.start': color.build('blue', 'default'), 'macro.name': color.build('yellow', 'default'), - 'macro.null': color.build('blue', 'default'), + 'macro.null': color.build('magenta', 'default'), 'macro.continued': color.build('red', 'default'), 'macro.char': color.build('green', 'default'), 'macro.string.start': color.build('green', 'default'), @@ -70,18 +87,12 @@ class C(mode2.Fundamental): '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'), - - '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'), + 'macro.end': color.build('magenta', 'default'), + 'label': color.build('magenta', 'default'), + 'keyword': color.build('cyan', 'default'), + 'function': color.build('blue', 'default'), + 'builtin': color.build('magenta', 'default'), 'structname': color.build('yellow', 'default'), 'enumname': color.build('yellow', 'default'), @@ -91,7 +102,6 @@ class C(mode2.Fundamental): 'string.escaped': color.build('green', 'default'), 'string.null': color.build('green', 'default'), 'string.end': color.build('green', 'default'), - 'integer': color.build('green', 'default'), 'float': color.build('green', 'default'),