diff --git a/mode/forth.py b/mode/forth.py index 576c786..8ed7743 100644 --- a/mode/forth.py +++ b/mode/forth.py @@ -1,16 +1,25 @@ from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, NocasePatternRule, NocaseRegionRule +from mode.python import StringGrammar2 class DataGrammar(Grammar): rules = [PatternRule(r'data', r'[^)]+')] +class StringGrammar1(Grammar): + rules = [PatternRule(r'data', r'[^\']+')] +class StringGrammar3(Grammar): + rules = [PatternRule(r'data', r'[^)]+')] + class ForthGrammar(Grammar): rules = [ PatternRule(r'comment', r"\\.*$"), RegionRule(r'comment', r'\(', DataGrammar, r'\)'), NocaseRegionRule(r'comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'), 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'(?<=:) +[^ ]+'), NocasePatternRule(r'number', r"'[a-z]"), NocasePatternRule(r'number', r'%?-?[0-1]+\.?'), @@ -24,7 +33,7 @@ class ForthGrammar(Grammar): class Forth(Fundamental): modename = 'FORTH' - extensions = ['.fs'] + extensions = ['.fs', '.fi', '.fb'] grammar = ForthGrammar commentc = '\\' colors = {