parent
ddd8828edd
commit
9bdaade444
108
mode/c.py
108
mode/c.py
|
@ -9,21 +9,26 @@ class CommentGrammar(Grammar):
|
||||||
PatternRule(r'data', r'(?:[^\*]|\*(?!/))+'),
|
PatternRule(r'data', r'(?:[^\*]|\*(?!/))+'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class ErrorGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(r'data', r'[^\\\n]+'),
|
||||||
|
PatternRule('continuation', r'\\\n$'),
|
||||||
|
]
|
||||||
|
|
||||||
class MacroGrammar(Grammar):
|
class MacroGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule('continuation', r'\\\n$'),
|
||||||
RegionRule(r'comment', r'/\*', CommentGrammar, r'\*/'),
|
PatternRule('name', r'(?<=#define ) *[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule(r'comment', r'//.*$'),
|
PatternRule('name', r'(?<=#ifdef ) *[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'),
|
PatternRule('name', r'(?<=#ifndef ) *[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule(r"unop", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
PatternRule('name', r'(?<=#undef ) *[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
PatternRule(r'concat', r'##[a-zA-Z0-9_]+'),
|
||||||
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
|
PatternRule(r'quoted', r'#[a-zA-Z0-9_]+'),
|
||||||
PatternRule(r"identifier", r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
PatternGroupRule(r'xyz',
|
||||||
PatternRule(r"integer", r"-?(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
r'function', r'defined',
|
||||||
PatternRule(r"float", r"-?(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)"),
|
r'delimiter', r'\(',
|
||||||
RegionRule(r'string', '"', StringGrammar2, '"'),
|
'name', r'[a-zA-Z_][a-zA-Z0-9_]*',
|
||||||
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
r'delimiter', r'\)'),
|
||||||
PatternRule(r"continued", r"\\\n$"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class CGrammar(Grammar):
|
class CGrammar(Grammar):
|
||||||
|
@ -35,28 +40,50 @@ class CGrammar(Grammar):
|
||||||
r' +', r'structname', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
r' +', r'structname', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternGroupRule(r'enumgroup', r'keyword', r'enum', r'spaces',
|
PatternGroupRule(r'enumgroup', r'keyword', r'enum', r'spaces',
|
||||||
r' +', r'enumname', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
r' +', r'enumname', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
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'builtin', r"(?:break|case|continue|default|do|else|for|goto|if|return|sizeof|switch|while)(?![a-zA-Z_])"),
|
||||||
|
PatternRule(r'type', r"(?:auto|char|const|double|enum|extern|float|int|long|register|short|signed|static|struct|typedef|union|unsigned|void|volatile)(?![a-zA-Z_])"),
|
||||||
|
|
||||||
|
PatternGroupRule(r'xyz',
|
||||||
|
r'type', r'[a-zA-Z_][a-zA-Z0-9_]*',
|
||||||
|
r'spaces', r' +', r'binop', r'\*+',
|
||||||
|
r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
PatternGroupRule(r'xyz',
|
||||||
|
r'type', r'[a-zA-Z_][a-zA-Z0-9_]*',
|
||||||
|
r'binop', r'\*+', r'spaces', r' +',
|
||||||
|
r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
PatternGroupRule(r'xyz',
|
||||||
|
r'type', r'[a-zA-Z_][a-zA-Z0-9_]*', r'spaces', r' +',
|
||||||
|
r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
|
||||||
PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
|
PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
|
||||||
PatternRule(r'builtin', r"(?:NULL|TRUE|FALSE)"),
|
PatternRule(r'constant', r"[A-Z_][A-Z0-9_]+"),
|
||||||
|
#PatternRule(r'builtin', r"(?:NULL|TRUE|FALSE)(?![a-zA-Z0-9_])"),
|
||||||
PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
|
PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
|
||||||
|
RegionRule(r'error', r'# *error', ErrorGrammar, r'\n$'),
|
||||||
RegionRule(r'macro', r'# *(?:assert|cpu|define|elif|else|endif|error|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma_once|pragma|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_once|pragma|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])', MacroGrammar, r'\n$'),
|
||||||
RegionRule(r'comment', r'/\*', CommentGrammar, r'\*/'),
|
RegionRule(r'comment', r'/\*', CommentGrammar, r'\*/'),
|
||||||
PatternRule(r'comment', r'//.*$'),
|
PatternRule(r'comment', r'//.*$'),
|
||||||
RegionRule(r'string', '"', StringGrammar2, '"'),
|
RegionRule(r'string', '"', StringGrammar2, '"'),
|
||||||
PatternRule(r"unop", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
#PatternRule(r"unop", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
||||||
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
#PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
||||||
|
PatternRule(r"operator", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
||||||
|
PatternRule(r'operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
||||||
PatternRule(r"integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
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]+"),
|
PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
||||||
RegionRule(r'macrocomment', r'#if +(?:0|NULL|FALSE)', Grammar, r'#endif'),
|
RegionRule(r'macrocomment', r'#if +(?:0|NULL|FALSE)', Grammar, r'#endif'),
|
||||||
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
||||||
PatternGroupRule(r'includegrp', r'macro.start', r'# *include', r'spaces',
|
PatternGroupRule(r'includegrp', r'macro.start', r'# *include', r'spaces',
|
||||||
r' +', r'header', r'< *[-A-Za-z/0-9_.]+ *>|" *[-A-Za-z/0-9_.]+ *"',
|
#r' +', r'header', r'< *[-A-Za-z/0-9_.]+ *>|" *[-A-Za-z/0-9_.]+ *"',
|
||||||
|
r' +', r'header', r'< *[-A-Za-z/0-9_.]+ *>|" *[-A-Za-z/0-9_.]+ *"|[A-Za-z0-9_]+',
|
||||||
'macro.end', r'\n$'),
|
'macro.end', r'\n$'),
|
||||||
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||||
OverridePatternRule(r'comment', r'/\* *@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *\*/$'),
|
OverridePatternRule(r'comment', r'/\* *@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *\*/$'),
|
||||||
OverridePatternRule(r'comment', r'// *@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
OverridePatternRule(r'comment', r'// *@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MacroGrammar.rules.extend(CGrammar.rules)
|
||||||
|
|
||||||
class CTabber2(tab.StackTabber2):
|
class CTabber2(tab.StackTabber2):
|
||||||
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
||||||
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
||||||
|
@ -102,41 +129,6 @@ class CTabber2(tab.StackTabber2):
|
||||||
return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start',
|
return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start',
|
||||||
'comment.data', 'comment.null', 'comment.end')
|
'comment.data', 'comment.null', 'comment.end')
|
||||||
|
|
||||||
#class CContext(context.Context):
|
|
||||||
# def _regen_stack(self, y):
|
|
||||||
# if y > 0 and self.namelines[y - 1][1]:
|
|
||||||
# return list(self.namelines[y - 1][1])
|
|
||||||
# else:
|
|
||||||
# return []
|
|
||||||
#
|
|
||||||
# def _build_name_map(self, y1, y2, last, curr, stack):
|
|
||||||
# highlights = self.mode.window.get_highlighter()
|
|
||||||
#
|
|
||||||
# i = y1
|
|
||||||
# while i < y2:
|
|
||||||
# if not stack: curr = None
|
|
||||||
# tokens = highlights.tokens[i]
|
|
||||||
#
|
|
||||||
# result = self.class_match.match(tokens)
|
|
||||||
# if result: curr = tokens[result[0] - self.class_offset].string
|
|
||||||
# result = self.method_match.match(tokens)
|
|
||||||
# if result: curr = tokens[result[0] - self.method_offset].string
|
|
||||||
#
|
|
||||||
# if curr is not None: self.names.setdefault(curr, i)
|
|
||||||
#
|
|
||||||
# for t in tokens:
|
|
||||||
# if t.match('delimiter', '{'):
|
|
||||||
# stack.append(curr)
|
|
||||||
# elif t.match('delimiter', '}'):
|
|
||||||
# if stack: stack.pop(-1)
|
|
||||||
# if stack:
|
|
||||||
# curr = stack[-1]
|
|
||||||
# else:
|
|
||||||
# curr = None
|
|
||||||
#
|
|
||||||
# if curr: self.namelines[i] = (curr, tuple(stack))
|
|
||||||
# i += 1
|
|
||||||
|
|
||||||
class CCheckSyntax(method.shell.Exec):
|
class CCheckSyntax(method.shell.Exec):
|
||||||
'''Build this C program (using the mode's make cmd)'''
|
'''Build this C program (using the mode's make cmd)'''
|
||||||
show_success = False
|
show_success = False
|
||||||
|
@ -186,8 +178,9 @@ class C(mode.Fundamental):
|
||||||
'macro.null': ('magenta', 'default', 'bold'),
|
'macro.null': ('magenta', 'default', 'bold'),
|
||||||
'macro.continued': ('red', 'default', 'bold'),
|
'macro.continued': ('red', 'default', 'bold'),
|
||||||
'macro.delimiter': ('default', 'default', 'bold'),
|
'macro.delimiter': ('default', 'default', 'bold'),
|
||||||
'macro.identifier': ('yellow', 'default', 'bold'),
|
'macro.concat': ('yellow', 'default', 'bold'),
|
||||||
'macro.bareword': ('yellow', 'default', 'bold'),
|
'macro.quoted': ('yellow', 'default', 'bold'),
|
||||||
|
#'macro.identifier': ('yellow', 'default', 'bold'),
|
||||||
'macro.integer': ('green', 'default', 'bold'),
|
'macro.integer': ('green', 'default', 'bold'),
|
||||||
'macro.float': ('green', 'default', 'bold'),
|
'macro.float': ('green', 'default', 'bold'),
|
||||||
'macro.char': ('green', 'default', 'bold'),
|
'macro.char': ('green', 'default', 'bold'),
|
||||||
|
@ -199,6 +192,11 @@ class C(mode.Fundamental):
|
||||||
'macro.end': ('magenta', 'default', 'bold'),
|
'macro.end': ('magenta', 'default', 'bold'),
|
||||||
'include': ('blue', 'default', 'bold'),
|
'include': ('blue', 'default', 'bold'),
|
||||||
'header': ('green', 'default', 'bold'),
|
'header': ('green', 'default', 'bold'),
|
||||||
|
'type': ('cyan', 'default', 'bold'),
|
||||||
|
'constant': ('yellow', 'default', 'bold'),
|
||||||
|
'error.start': ('blue', 'default', 'bold'),
|
||||||
|
'error.data': ('green', 'default', 'bold'),
|
||||||
|
'error.null': ('green', 'default', 'bold'),
|
||||||
}
|
}
|
||||||
config = {
|
config = {
|
||||||
'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",
|
'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",
|
||||||
|
|
Loading…
Reference in New Issue