diff --git a/mode/forth.py b/mode/forth.py index 3084805..f7c6505 100644 --- a/mode/forth.py +++ b/mode/forth.py @@ -7,6 +7,13 @@ from mode.python import StringGrammar2 from mode.pipe import Pipe from method.shell import Interact +class CodeGrammar(Grammar): + rules = [ + PatternRule('word', r'[^ ]+'), + PatternRule('spaces', r' +'), + PatternRule('eol', r' +'), + ] + class DataGrammar(Grammar): rules = [PatternRule('data', r'[^)]+')] class LineGrammar(Grammar): rules = [PatternRule('data', r'.+')] class StringGrammar3(Grammar): rules = [PatternRule('data', r'[^)]+')] @@ -40,6 +47,7 @@ class ForthGrammar(Grammar): NocasePatternRule('builtin', r'(?:constant|2constant|fconstant|variable|2variable|fvariable|create|user|to|defer|is|does>|immediate|compile-only|compile|restrict|interpret|postpone|execute|literal|create-interpret/compile|interpretation>||int|name\?int|name>comp|name>string|state|c;|cvariable|,|2,|f,|c,|\[(?:ifdef|ifundef|then|endif|then|else|\?do|do|loop|\+loop|next|begin|until|again|while|repeat|comp\'|\'|compile)\])(?= |\n|$)'), # assembly (*) + NocaseRegionRule('code', 'code', CodeGrammar, 'end-code'), NocasePatternRule('builtin', r'(?:assembler|code|end-code|;code|flush-icache|c,)(?= |\n|$)'), # xyz @@ -50,7 +58,7 @@ class ForthGrammar(Grammar): NocasePatternRule('number', r'[&#]?-?[0-9]+\.?(?= |$)'), NocasePatternRule('number', r"(?:0x|\$)[0-9a-f]+\.?(?= |$)"), NocasePatternRule('number', r'[+-]?[0-9]+\.?e?[+-][0-9]+(?= |$)'), - PatternRule('forth_word', r'[^ ]+'), + PatternRule('forth.word', r'[^ ]+'), PatternRule('spaces', r' +'), PatternRule('eol', r'\n'), ] @@ -115,7 +123,8 @@ class Forth(Fundamental): actions = [GforthStart, GforthLoadFile] tabbercls = ForthTabber colors = { - 'forth_word': ('yellow', 'default', 'bold'), + 'forth.word': ('yellow', 'default', 'bold'), + 'forth.code': ('green', 'default', 'bold'), } def install(*args):