--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-10-25 10:43:22 -04:00
commit 707554621b
4 changed files with 20 additions and 11 deletions

4
lex.py
View File

@ -351,8 +351,8 @@ class RegionRule(Rule):
if self.pairs[i][1]:
try:
stopre = re.compile(self.pairs[i][1] % matchd, self.reflags)
except:
raise Exception, "%r\n%r\n%r" % (self.pairs[i][1], matchd, self.reflags)
except Exception, e:
raise Exception, "%r\n%r\n%r\n%r" % (e, self.pairs[i][1], matchd, self.reflags)
else:
stopre = None
if i == len(self.pairs) - 1:

View File

@ -11,26 +11,30 @@ word = chr1 + chr2 + '*'
class NasmGrammar(Grammar):
rules = [
PatternRule('comment', ';.*$'),
RegionRule('comment', '%if +0', Grammar, r'%%endif'),
# for use with ndisasm files
PatternRule('nasm.address', '^[0-9a-fA-F]+ +[0-9a-fA-F]+'),
PatternMatchRule('x', '^([0-9a-fA-F]{8})( )([0-9a-fA-F]+)', 'nasm.integer', 'spaces', 'nasm.address'),
PatternRule('nasm.address', '^[0-9a-fA-F]{8} [0-9a-fA-F]+'),
PatternRule('spaces', ' +'),
PatternRule("nasm.integer", "(0[xX][0-9a-fA-F]+|0|[1-9][0-9]*|0[0-7]+)[lL]?"),
PatternRule('nasm.register', "(?:eax|ebx|ecx|edx|ax|ah|al|bx|bh|bl|bp|cx|ch|cl|cmpsb|dh|di|dl|ds|dx|esi|es|edi|esp|ebp|si|sp|stosd)(?!" + chr2 + ")"),
PatternRule('nasm.pseudo', "(?:a16|a32|byte|db|dd|do|dq|dt|dword|qword|tword|fs|gs|near|o16|o32|short)(?!" + chr2 + ")"),
PatternRule('nasm.instruction', "(?:jg|jeq|jecxz|jne|ja|jmp|push|pushad|pushfd|call|ret|sub|adc|add|popad|popaw|popa|popfd|pop|call|and|arpl|bound|cwd|cdq|clc|cld|cli|cmp|cmpxchg|cpuid|das|dec|divpd|div|enter|leave|fadd|fld|fmul|fsqrt|fsub|fs|hlt|imul|inc|insb|insd|insw|ins|int|int3|in|jcxz|jc|jna|jnc|jnz|jo|js|jz|lea|lldt|loadsb|lock|loopne|movzx|movd|mov|mul|neg|not|nop|or|outsb|outsd|outsw|repe|retf|rol|sal|sar|sbb|scasw|shl|shr|shld|shrd|sldt|syscall|sysenter|sysexit|test|xchg|xadd|xor)(?!" + chr2 + ")"),
PatternRule('nasm.macro', "%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"),
PatternRule('nasm.macro', "\%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"),
PatternRule('nasm.keyword', "(?:section|global|extern)(?!" + chr2 + ")"),
PatternRule('nasm.prefix', "(?:dword|word|lock)(?!" + chr2 + ")"),
PatternMatchRule('x', '(' + word + ')(:)', 'nasm.label', 'delimiter'),
PatternRule("nasm.identifier", r'\$?' + word),
PatternRule("nasm.float", r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
PatternRule('delimiter', r'(?://|%%|<<|>>|[~!\.\*/%\-\+\(\)\[\],\|\^\&])'),
# TODO: nasm strings seem like they are single-line only
RegionRule('string', '"""', StringGrammar4, '"""'),
RegionRule('string', "'''", StringGrammar3, "'''"),
RegionRule('string', '"', StringGrammar2, '"'),
RegionRule('string', "'", StringGrammar1, "'"),
PatternRule('comment', ';.*$'),
PatternRule('eol', '\n'),
PatternRule('continuation', r'\\\n$'),
]

View File

@ -24,8 +24,8 @@ class RSTGrammar(Grammar):
RegionRule(r'strong_emphasis', r'\*\*', RSTString1, r'\*\*'),
RegionRule(r'emphasis', r'\*', RSTString1, r'\*'),
RegionRule(r'inline_literal', r'``', RSTString2, r'``'),
RegionRule(r'interpreted', r'`', RSTString2, r'`_?'),
#RegionRule(r'inline_literal', r'``', RSTString2, r'``'),
#RegionRule(r'interpreted', r'`', RSTString2, r'`_?'),
PatternRule(r'anonymous', r'[a-zA-Z]+__'),
PatternRule(r'reference', r'[a-zA-Z]+_(?![a-zA-Z0-9_])'),

View File

@ -39,10 +39,14 @@ class ScalaGrammar(Grammar):
RegionRule('scala.comment', r'/\*', NestedCommentGrammar, r'\*/'),
RegionRule('scala.script', r'#!.+$', ShGrammar, r'!#'),
PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)',
PatternMatchRule('x', r'(:)([a-zA-Z0-9_]+)',
'delimiter', 'scala.type'),
PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)',
PatternMatchRule('x', r'(:)( +)([a-zA-Z0-9_]+)',
'delimiter', 'spaces', 'scala.type'),
#PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)',
# 'delimiter', 'scala.type'),
#PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)',
# 'delimiter', 'spaces', 'scala.type'),
PatternMatchRule('x', r'(extends)( +)([a-zA-Z0-9_]+)',
'scala.reserved', 'spaces', 'scala.type'),
@ -50,6 +54,7 @@ class ScalaGrammar(Grammar):
'scala.reserved', 'spaces', 'scala.type'),
#PatternRule('delimiter', r'(?:;|{|}|\[|\]|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'),
RegionRule('sub', r'(?<=:)\(', SubTypeGrammar, r'\)'),
PatternRule('delimiter', r'(?:;|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'),
RegionRule('sub', r'\[', SubTypeGrammar, r'\]'),
@ -65,7 +70,7 @@ class ScalaGrammar(Grammar):
PatternRule('scala.pseudo', '(?:true|null|false)'),
PatternRule('scala.reserved', '(?:yield|with|while|var|val|until|type|true|try|trait|throw|this|super|sealed|return|protected|private|package|override|object|null|new|match|lazy|import|implicit|if|forSome|for|finally|final|false|extends|else|do|def|class|catch|case|abstract)(?!%s)' % word),
PatternRule('scala.reserved', '(?:yield|with|while|var|val|until|type|true|try|trait|throw|to|this|super|sealed|return|protected|private|package|override|object|null|new|match|lazy|import|implicit|if|forSome|for|finally|final|false|extends|else|do|def|class|catch|case|abstract)(?!%s)' % word),
PatternRule('scala.integer', '-?(?:0|[1-9])[0-9]*[Ll]?'),
PatternRule('scala.integer', '-?0x[0-9A-Fa-f]+[Ll]?'),