From 83c7ea1fb9637d2d617ab8f1412eb2fc98ab5742 Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 11 Mar 2009 19:08:26 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- mode/forth.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mode/forth.py b/mode/forth.py index 8ed7743..671cd8e 100644 --- a/mode/forth.py +++ b/mode/forth.py @@ -1,6 +1,8 @@ +import time from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, NocasePatternRule, NocaseRegionRule from mode.python import StringGrammar2 +from method.shell import Interact class DataGrammar(Grammar): rules = [PatternRule(r'data', r'[^)]+')] @@ -12,13 +14,14 @@ class StringGrammar3(Grammar): class ForthGrammar(Grammar): rules = [ - PatternRule(r'comment', r"\\.*$"), - RegionRule(r'comment', r'\(', DataGrammar, r'\)'), + PatternRule(r'comment', r"\\(?: .*)?\n$"), + RegionRule(r'comment', r'\((?= |\n)', DataGrammar, r'\)'), NocaseRegionRule(r'comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'), PatternRule(r'delimiter', r"[:;\[\]]"), RegionRule(r'string', r'[.cs]" ', StringGrammar1, r'"'), RegionRule(r'string', r'[.s]\\" ', StringGrammar2, r'"'), - RegionRule(r'string', r'.\( ', StringGrammar3, r'\)'), + RegionRule(r'string', r'\.\( ', StringGrammar3, r'\)'), + PatternRule(r'operator', r'(?:mod|m\*|f\+|f-|f\*|f/|\+|-|\*/mod|\*/|\*|/mod|/)(?=[ \n$])'), 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]"), @@ -31,6 +34,19 @@ class ForthGrammar(Grammar): PatternRule(r'eol', r'\n'), ] +class GforthStart(Interact): + args = [] + def _execute(self, w, **vargs): + Interact._execute(self, w, bname='*GForth*', cmd='gforth') +class GforthLoadFile(Interact): + args = [] + def _execute(self, w, **vargs): + Interact._execute(self, w, bname='*GForth*', cmd='gforth') + b = w.application.get_buffer_by_name('*GForth*') + time.sleep(0.1) + for line in w.buffer.lines: + b.pipe_write(line + '\n') + class Forth(Fundamental): modename = 'FORTH' extensions = ['.fs', '.fi', '.fb'] @@ -40,5 +56,6 @@ class Forth(Fundamental): 'forth_def': ('blue', 'default', 'bold'), 'forth_word': ('yellow', 'default', 'bold'), } + actions = [GforthStart, GforthLoadFile] install = Forth.install