branch : pmacs2
This commit is contained in:
moculus 2007-07-11 09:28:08 +00:00
parent 9258c8e0b4
commit f7c92804e7
1 changed files with 23 additions and 26 deletions

View File

@ -7,43 +7,40 @@ from mode_python import StringGrammar
class MacroGrammar(Grammar): class MacroGrammar(Grammar):
rules = [ rules = [
PatternRule(name='name', pattern=r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(name='continued', pattern=r'\\ *$'), PatternRule('continued', r'\\ *$'),
RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'), RegionRule(r'string', '"', StringGrammar(), '"'),
PatternRule(name=r'char', pattern=r"'.'|'\\.'|'\\[0-7]{3}'") PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'")
] ]
class CGrammar(Grammar): class CGrammar(Grammar):
rules = [ rules = [
PatternRule(name=r'include', pattern=r'#include(?!=[a-zA-Z0-9_])'), PatternRule(r'include', r'#include(?!=[a-zA-Z0-9_])'),
PatternRule(name=r'header', pattern=r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'), PatternRule(r'header', r'<[-A-Za-z/0-9_\.]+>|"[-A-Za-z/0-9_\.]+"'),
PatternRule(name=r'macro', pattern=r'#(?:endif)'), PatternRule(r'macro', r'#(?:endif)'),
RegionRule( 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'[^\\ ] *$'),
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_])', PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
grammar=MacroGrammar(), RegionRule(r'comment1', '/\*', Grammar(), '\*/'),
end=r'[^\\ ] *$', 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(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'structname', r'(?<=struct ) *[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'enumname', r'(?<=enum ) *[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(name=r'builtin', pattern=r"(?:NULL|TRUE|FALSE)"), PatternRule(r'builtin', r"(?:NULL|TRUE|FALSE)"),
PatternRule(name=r'identifier', pattern=r"[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
PatternRule(name=r"unop", pattern=r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(name=r'binop', pattern=r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
# this is sketchy as hell # this is sketchy as hell
PatternRule(name=r"delimiter", pattern=r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"), PatternRule(r"delimiter", 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]+"), PatternRule(r"integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'), PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
PatternRule(name=r'char', pattern=r"'.'|'\\.'|'\\[0-7]{3}'") RegionRule(r'string', '"', StringGrammar(), '"'),
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'")
] ]
class C(mode2.Fundamental): class C(mode2.Fundamental):