Ejemplo n.º 1
0
    def __init__(self, backend, working_dir=None, options=None, name=None, src_text=None, is_stdlib_cache=False):
        # assert src_text is None
        from neurounits.neurounitparser import NeuroUnitParserOptions

        self.options = options or NeuroUnitParserOptions()

        # This is only used to make summarising easier:

        self.name = name
        self.src_text = src_text

        self.currentblock = None
        self.backend = backend

        self.libraries = []
        self.eqnsets = []

        # self.working_dir = working_dir or "/tmp/mf_neurounits/"
        # EnsureExisits(self.working_dir)

        if is_stdlib_cache:
            # Load in the standard libraries:
            from neurounits.unit_expr_parsing.units_expr_yacc import parse_expr, ParseTypes

            LibraryManager._stdlib_cache_loading = True
            for f in glob.glob(self._stdlibdir + "/*.eqn"):
                with open(f) as l:
                    parse_expr(l.read(), parse_type=ParseTypes.L6_TextBlock, library_manager=self)

            LibraryManager._stdlib_cache_loading = False
            LibraryManager._stdlib_cache = self

        # Ensure the cache is setup:
        if not LibraryManager._stdlib_cache and not is_stdlib_cache:
            LibraryManager(backend=backend, is_stdlib_cache=True)
Ejemplo n.º 2
0
 def Function(cls, text, debug=False, backend=None):
     assert False
     """ Should return a callable"""
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(
         text,
         parse_type=units_expr_yacc.ParseTypes.L1_Unit,
         backend=backend)
Ejemplo n.º 3
0
    def __init__(self,
                 backend,
                 working_dir=None,
                 options=None,
                 name=None,
                 src_text=None,
                 is_stdlib_cache=False):
        from neurounits.neurounitparser import NeuroUnitParserOptions
        self.options = options or NeuroUnitParserOptions()

        # This is only used to make summarising easier:

        self.name = name
        self.src_text = src_text

        self.block_stack = []

        self.backend = backend

        self._parsing_namespace_stack = []

        # And into these:
        self.namespace = ComponentNamespace(name=None, parent=None)

        if is_stdlib_cache and not LibraryManager._stdlib_cache:
            # Load in the standard libraries:
            from neurounits.unit_expr_parsing.units_expr_yacc import parse_expr, ParseTypes
            LibraryManager._stdlib_cache_loading = True
            for f in glob.glob(self._stdlibdir + '/*.eqn'):
                with open(f) as l:
                    print 'Loading StdLib file:', f
                    parse_expr(l.read(),
                               parse_type=ParseTypes.N6_9MLFile,
                               library_manager=self)

            LibraryManager._stdlib_cache_loading = False
            # Copy the old namespace object accross
            LibraryManager._stdlib_cache = self.namespace
            self.namespace = ComponentNamespace(name=None, parent=None)

        # Ensure the cache is setup:
        if not LibraryManager._stdlib_cache and not is_stdlib_cache:
            LibraryManager(backend=backend, is_stdlib_cache=True)
Ejemplo n.º 4
0
    def __init__(self,
                 backend,
                 working_dir=None,
                 options=None,
                 name=None,
                 src_text=None,
                 is_stdlib_cache=False):
        #assert src_text is None
        from neurounits.neurounitparser import NeuroUnitParserOptions
        self.options = options or NeuroUnitParserOptions()

        # This is only used to make summarising easier:

        self.name = name
        self.src_text = src_text

        self.currentblock = None
        self.backend = backend

        self.libraries = []
        self.eqnsets = []

        # self.working_dir = working_dir or "/tmp/mf_neurounits/"
        # EnsureExisits(self.working_dir)

        if is_stdlib_cache:
            # Load in the standard libraries:
            from neurounits.unit_expr_parsing.units_expr_yacc import parse_expr, ParseTypes
            LibraryManager._stdlib_cache_loading = True
            for f in glob.glob(self._stdlibdir + "/*.eqn"):
                with open(f) as l:
                    print 'Loading StdLib file:', f
                    parse_expr(l.read(),
                               parse_type=ParseTypes.L6_TextBlock,
                               library_manager=self)

            LibraryManager._stdlib_cache_loading = False
            LibraryManager._stdlib_cache = self

        # Ensure the cache is setup:
        if not LibraryManager._stdlib_cache and not is_stdlib_cache:
            LibraryManager(backend=backend, is_stdlib_cache=True)
Ejemplo n.º 5
0
    def __init__(self,backend, working_dir=None, options=None, name=None, src_text=None, is_stdlib_cache=False):
        from neurounits.neurounitparser import NeuroUnitParserOptions
        self.options = options or NeuroUnitParserOptions()

        # This is only used to make summarising easier:

        self.name = name
        self.src_text = src_text

        self.block_stack = []

        self.backend = backend

     

        self._parsing_namespace_stack = []

        # And into these:
        self.namespace = ComponentNamespace(name=None, parent=None)

        if is_stdlib_cache and not LibraryManager._stdlib_cache:
            # Load in the standard libraries:
            from neurounits.unit_expr_parsing.units_expr_yacc import parse_expr, ParseTypes
            LibraryManager._stdlib_cache_loading = True
            for f in glob.glob(self._stdlibdir + '/*.eqn'):
                with open(f) as l:
                    print 'Loading StdLib file:', f
                    parse_expr(l.read(), parse_type=ParseTypes.N6_9MLFile, library_manager=self)

            LibraryManager._stdlib_cache_loading = False
            # Copy the old namespace object accross
            LibraryManager._stdlib_cache = self.namespace
            self.namespace = ComponentNamespace(name=None, parent=None)


        # Ensure the cache is setup:
        if not LibraryManager._stdlib_cache and not is_stdlib_cache:
            LibraryManager(backend=backend, is_stdlib_cache=True)
Ejemplo n.º 6
0
 def File(cls,
          text,
          working_dir=None,
          debug=False,
          backend=None,
          options=None,
          name=None):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(
         text,
         parse_type=units_expr_yacc.ParseTypes.L6_TextBlock,
         working_dir=working_dir,
         backend=backend,
         options=options,
         name=name)
Ejemplo n.º 7
0
 def Parse9MLFile(cls,
                  text,
                  debug=False,
                  backend=None,
                  working_dir=None,
                  options=None,
                  **kwargs):
     logging.log_neurounits.info('Parse9MLFile:')
     logging.log_neurounits.info('Options: %s' % options)
     logging.log_neurounits.info('Text: \n%s' % text)
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(
         text,
         parse_type=units_expr_yacc.ParseTypes.N6_9MLFile,
         working_dir=working_dir,
         backend=backend,
         options=options,
         **kwargs)
Ejemplo n.º 8
0
 def QuantityExpr(cls, text, debug=False, backend=None):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(
         text,
         parse_type=units_expr_yacc.ParseTypes.L3_QuantityExpr,
         backend=backend)
Ejemplo n.º 9
0
 def Unit(cls, text, debug=False, backend=None):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(
         text,
         parse_type=units_expr_yacc.ParseTypes.L1_Unit,
         backend=backend)
Ejemplo n.º 10
0
 def File(cls, text, working_dir=None, debug=False, backend=None, options=None, name=None ):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(text, parse_type=units_expr_yacc.ParseTypes.L6_TextBlock, working_dir=working_dir, backend=backend, options=options, name=name)
Ejemplo n.º 11
0
 def Function(cls, text, debug=False, backend=None):
     assert False
     """ Should return a callable"""
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(text, parse_type=units_expr_yacc.ParseTypes.L1_Unit, backend=backend )
Ejemplo n.º 12
0
 def QuantityExpr(cls, text, debug=False, backend=None):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(text, parse_type=units_expr_yacc.ParseTypes.L3_QuantityExpr, backend=backend)
Ejemplo n.º 13
0
 def Unit(cls, text, debug=False, backend=None):
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(text, parse_type=units_expr_yacc.ParseTypes.L1_Unit, backend=backend )
Ejemplo n.º 14
0
 def Parse9MLFile(cls, text, debug=False, backend=None, working_dir=None, options=None, **kwargs):
     logging.log_neurounits.info('Parse9MLFile:')
     logging.log_neurounits.info('Options: %s'%options)
     logging.log_neurounits.info('Text: \n%s' % text)
     backend = backend or cls.get_defaultBackend()
     return units_expr_yacc.parse_expr(text, parse_type=units_expr_yacc.ParseTypes.N6_9MLFile, working_dir=working_dir, backend=backend, options=options, **kwargs)