Beispiel #1
0
 def __repr__(self): 
   if run_mode()==interactive:
     set_run_mode(noninteractive)
     code  = interactive_parser().parse(self.exp)
     code  = interactive_tagger().tag_loop_label(code)
     result = "%s"%code
     set_run_mode(interactive)
     return result
   else: 
     return "'%s"%self.exp
Beispiel #2
0
from dao.builtins.control import fail, or_p, and_p, not_p, cut

from dao.special import function, let, letr, macro, begin, eval_
from dao.builtins.arith import add
from dao.builtins.parser import set_text, parse_text
from dao.builtins.parser import step, left, next_char, position, subtext, goto, skip
from dao.builtins.terminal import char, number, eoi, literal, letter 
from dao.builtins.terminal import dqstring, sqstring, spaces, uLetterdigitString
from dao.builtins.matcher import nullword, optional, parallel
from dao.builtins.matcher import any, some, times, times_more, times_less, seplist
from dao.builtins.matcher import lazy, times_between
from dao.builtins.container import contain
from dao.util import *

from dao.solve import set_run_mode, noninteractive
set_run_mode(noninteractive)

def eval(exp):
  exp = preparse(exp)
  sexp = to_sexpression(exp)
  return make_solver().eval(sexp)

class TestLowLevelPrimitive:
  def test_step(self):
    eq_(eval(begin(set_text('ab'), step(), step())), 'b')
    eq_(eval(begin(set_text('ab'), step(), left())), 'b')
  def test_next(self):
    eq_(eval(begin(set_text('ab'), next_char(), next_char())), 'a')
  def test_left(self):
    eq_(eval(begin(set_text('ab'), left())), 'ab')
  def test_position(self):
Beispiel #3
0
from dao.solve import make_solver, set_run_mode, noninteractive
from dao import builtin

from dao.special import *
from dao.builtins.arith import *
from dao.builtins.control import *
from dao.builtins.io import *
from dao.builtins.container import *
from dao.builtins.parser import *
from dao.builtins.matcher import *
from dao.builtins.terminal import *
from dao.builtins.rule import *
from dao.builtins.term import *
from dao.builtins.quasiquote import *

set_run_mode(noninteractive)

from dao.base import is_subclass

_builtins = {}


def collocet_builtins():
    for name, obj in globals().items():
        if isinstance(obj, Command) or is_subclass(obj, SpecialForm):
            try:
                symbol = obj.symbol
            except AttributeError:
                try:
                    symbol = obj.name
                except AttributeError:
Beispiel #4
0
from dao.special import quote, eval_, catch, throw, pytry
from dao.term import cons, conslist, nil

from dao.dinpy.dexpr import *
from dao.dinpy.dinpy import *
from dao.dinpy.vars import *

from dao.dinpy.arith import *
from dao.dinpy.control import *
from dao.dinpy.io import *
from dao.dinpy.container import *
from dao.dinpy.parser import *
from dao.dinpy.term import *

from dao.solve import set_run_mode
set_run_mode(mode=interactive)

__all__ = globals().keys()+['_']
Beispiel #5
0
 def test_parse_interactive(self):
     from dao.solve import set_run_mode, interactive
     set_run_mode(mode=interactive)
     from dao.dinpy.samples import parse_interactive
Beispiel #6
0
from dao.special import quote, eval_, catch, throw, pytry
from dao.term import cons, conslist, nil

from dao.dinpy.dexpr import *
from dao.dinpy.dinpy import *
from dao.dinpy.vars import *

from dao.dinpy.arith import *
from dao.dinpy.control import *
from dao.dinpy.io import *
from dao.dinpy.container import *
from dao.dinpy.parser import *
from dao.dinpy.term import *

from dao.solve import set_run_mode

set_run_mode(mode=interactive)

__all__ = globals().keys() + ['_']
Beispiel #7
0
 def test_parse_interactive(self):
   from dao.solve import set_run_mode, interactive
   set_run_mode(mode=interactive)
   from dao.dinpy.samples import parse_interactive
Beispiel #8
0
 def __getitem__(self, code):
     set_run_mode(noninteractive)
     if isinstance(code, tuple): self.code += list(code)
     else: self.code += [code]
     return self
Beispiel #9
0
 def __getitem__(self, code):
   set_run_mode(noninteractive)
   if isinstance(code, tuple): self.code +=  list(code)
   else: self.code += [code]
   return self