branch : pmacs2
This commit is contained in:
moculus 2009-03-11 02:58:22 +00:00
parent 66998865eb
commit 553e968615
1 changed files with 11 additions and 2 deletions

View File

@ -1,16 +1,25 @@
from mode import Fundamental from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule, NocasePatternRule, NocaseRegionRule from lex import Grammar, PatternRule, RegionRule, NocasePatternRule, NocaseRegionRule
from mode.python import StringGrammar2
class DataGrammar(Grammar): class DataGrammar(Grammar):
rules = [PatternRule(r'data', r'[^)]+')] rules = [PatternRule(r'data', r'[^)]+')]
class StringGrammar1(Grammar):
rules = [PatternRule(r'data', r'[^\']+')]
class StringGrammar3(Grammar):
rules = [PatternRule(r'data', r'[^)]+')]
class ForthGrammar(Grammar): class ForthGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r"\\.*$"), PatternRule(r'comment', r"\\.*$"),
RegionRule(r'comment', r'\(', DataGrammar, r'\)'), RegionRule(r'comment', r'\(', DataGrammar, r'\)'),
NocaseRegionRule(r'comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'), NocaseRegionRule(r'comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'),
PatternRule(r'delimiter', r"[:;\[\]]"), PatternRule(r'delimiter', r"[:;\[\]]"),
NocasePatternRule(r'keyword', r'(?:variable|value|until|tuck|truth|to|then|test|swap|step|see|rot|roll|recurse|r>|pick|over|mod|m\*|loop|locals|invert|if|hex|here|fsort|fln|fexp|f!|f@|f\+|f-|f\*|f/|execute|endif|else|dup|drop|does>|do|decimal|d!|d@|create|constant|cells|cell|c!|c@|bye|begin|allot|\[(?:if|then|endif)\]|>r|!|@|\+loop|\+|-|\*/mod|\*/|\*|/mod|/)(?=[ \n])'), RegionRule(r'string', r'[.cs]" ', StringGrammar1, r'"'),
RegionRule(r'string', r'[.s]\\" ', StringGrammar2, r'"'),
RegionRule(r'string', r'.\( ', StringGrammar3, r'\)'),
NocasePatternRule(r'keyword', r'(?:variable|value|until|tuck|truth|to|then|test|swap|step|see|rot|roll|recurse|r>|pick|over|mod|m\*|loop|locals|invert|if|hex|here|fsort|fln|fexp|f!|f@|f\+|f-|f\*|f/|execute|endif|else|dup|drop|does>|do|decimal|d!|d@|create|constant|cells|cell|c!|c@|bye|begin|allot|\[(?:if|then|endif)\]|>r|!|@|\+loop|\+|-|\*/mod|\*/|\*|/mod|/)(?=[ \n$])'),
PatternRule(r'forth_def', r'(?<=:) +[^ ]+'), PatternRule(r'forth_def', r'(?<=:) +[^ ]+'),
NocasePatternRule(r'number', r"'[a-z]"), NocasePatternRule(r'number', r"'[a-z]"),
NocasePatternRule(r'number', r'%?-?[0-1]+\.?'), NocasePatternRule(r'number', r'%?-?[0-1]+\.?'),
@ -24,7 +33,7 @@ class ForthGrammar(Grammar):
class Forth(Fundamental): class Forth(Fundamental):
modename = 'FORTH' modename = 'FORTH'
extensions = ['.fs'] extensions = ['.fs', '.fi', '.fb']
grammar = ForthGrammar grammar = ForthGrammar
commentc = '\\' commentc = '\\'
colors = { colors = {