How to use the tatsu.semantics.ModelBuilderSemantics function in TatSu

To help you get started, we’ve selected a few TatSu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / TextWorld / textworld / textgen / model.py View on Github external
#    https://pypi.python.org/pypi/tatsu/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.

from __future__ import print_function, division, absolute_import, unicode_literals

from tatsu.objectmodel import Node
from tatsu.semantics import ModelBuilderSemantics


class ModelBase(Node):
    pass


class TextGrammarModelBuilderSemantics(ModelBuilderSemantics):
    def __init__(self, context=None, types=None):
        types = [
            t for t in globals().values()
            if type(t) is type and issubclass(t, ModelBase)
        ] + (types or [])
        super(TextGrammarModelBuilderSemantics, self).__init__(context=context, types=types)


class Literal(ModelBase):
    value = None


class AdjectiveNoun(ModelBase):
    adjective = None
    noun = None
github neogeny / TatSu / examples / calc / v5 / calc_model.py View on Github external
# CAVEAT UTILITOR
#
# This file was automatically generated by TatSu.
#
#    https://pypi.python.org/pypi/tatsu/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.

from __future__ import print_function, division, absolute_import, unicode_literals

from tatsu.objectmodel import Node
from tatsu.semantics import ModelBuilderSemantics


class CalcModelBuilderSemantics(ModelBuilderSemantics):
    def __init__(self):
        types = [
            t for t in globals().values()
            if type(t) is type and issubclass(t, ModelBase)
        ]
        super(CalcModelBuilderSemantics, self).__init__(types=types)


class ModelBase(Node):
    pass


class Add(ModelBase):
    def __init__(self,
                 left=None,
                 op=None,
github neogeny / TatSu / tatsu / tool.py View on Github external
def compile(grammar, name=None, semantics=None, asmodel=False, **kwargs):
    cache = __compiled_grammar_cache

    if (grammar, semantics) in cache:
        model = cache[(grammar, semantics)]
    else:
        gen = GrammarGenerator(name, **kwargs)
        model = cache[grammar] = gen.parse(grammar, **kwargs)
        model.semantics = semantics or asmodel and ModelBuilderSemantics()
    return model
github neogeny / TatSu / examples / javascript / sandbojs / parser / js_model.py View on Github external
#    https://pypi.python.org/pypi/tatsu/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.

from __future__ import print_function, division, absolute_import, unicode_literals

from tatsu.objectmodel import Node
from tatsu.semantics import ModelBuilderSemantics


class ModelBase(Node):
    pass


class JavaScriptModelBuilderSemantics(ModelBuilderSemantics):
    def __init__(self, context=None, types=None):
        types = [
            t for t in globals().values()
            if type(t) is type and issubclass(t, ModelBase)
        ] + (types or [])
        super(JavaScriptModelBuilderSemantics, self).__init__(context=context, types=types)


class Integer(ModelBase):
    value = None


class Float(ModelBase):
    value = None
github microsoft / TextWorld / textworld / logic / model.py View on Github external
#    https://pypi.python.org/pypi/tatsu/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.

from __future__ import print_function, division, absolute_import, unicode_literals

from tatsu.objectmodel import Node
from tatsu.semantics import ModelBuilderSemantics


class ModelBase(Node):
    pass


class GameLogicModelBuilderSemantics(ModelBuilderSemantics):
    def __init__(self, context=None, types=None):
        types = [
            t for t in globals().values()
            if type(t) is type and issubclass(t, ModelBase)
        ] + (types or [])
        super(GameLogicModelBuilderSemantics, self).__init__(context=context, types=types)


class VariableNode(ModelBase):
    name = None
    type = None


class SignatureNode(ModelBase):
    name = None
    types = None
github neogeny / TatSu / examples / calc / v6 / calc_model.py View on Github external
# CAVEAT UTILITOR
#
# This file was automatically generated by TatSu.
#
#    https://pypi.python.org/pypi/tatsu/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.

from __future__ import print_function, division, absolute_import, unicode_literals

from tatsu.objectmodel import Node
from tatsu.semantics import ModelBuilderSemantics


class CalcModelBuilderSemantics(ModelBuilderSemantics):
    def __init__(self):
        types = [
            t for t in globals().values()
            if type(t) is type and issubclass(t, ModelBase)
        ]
        super(CalcModelBuilderSemantics, self).__init__(types=types)


class ModelBase(Node):
    pass


class Add(ModelBase):
    def __init__(self,
                 left=None,
                 op=None,