parent
9258c8e0b4
commit
f7c92804e7
49
mode_c.py
49
mode_c.py
|
@ -7,43 +7,40 @@ from mode_python import StringGrammar
|
|||
|
||||
class MacroGrammar(Grammar):
|
||||
rules = [
|
||||
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}'")
|
||||
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}'")
|
||||
]
|
||||
|
||||
class CGrammar(Grammar):
|
||||
rules = [
|
||||
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|ident|ifdef|ifndef|if|import|include_next|line|machine|pragma|pragma_once|system|unassert|undef|warning)(?!=[a-zA-Z0-9_])',
|
||||
grammar=MacroGrammar(),
|
||||
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'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'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'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
|
||||
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'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"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
||||
PatternRule(r'builtin', r"(?:NULL|TRUE|FALSE)"),
|
||||
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
||||
PatternRule(r'binop', 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]?"),
|
||||
PatternRule(name=r"float", pattern=r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
||||
RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'),
|
||||
PatternRule(name=r'char', pattern=r"'.'|'\\.'|'\\[0-7]{3}'")
|
||||
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
|
||||
|
||||
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(), '"'),
|
||||
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'")
|
||||
]
|
||||
|
||||
class C(mode2.Fundamental):
|
||||
|
|
Loading…
Reference in New Issue