diff options
author | Juergen Bocklage-Ryannel <juergen@ryannel.org> | 2018-03-07 18:33:15 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <juergen@ryannel.org> | 2018-03-07 18:33:15 +0100 |
commit | 183aeabc79e8d0791d9b6583923a3bd091663686 (patch) | |
tree | 7d86c9b5758650ae10bdb02111853be7df8e3b67 | |
parent | e04a782de7161828b945b58aee12a22c0906a9f1 (diff) | |
parent | c7b805476b038a0f60257b5ddfb8ebfc065bf62f (diff) |
Merge branch 'feature/profile' into develop
# Conflicts:
# qface/idl/profile.py
-rw-r--r-- | qface/idl/listener.py | 29 | ||||
-rw-r--r-- | qface/idl/profile.py | 54 |
2 files changed, 54 insertions, 29 deletions
diff --git a/qface/idl/listener.py b/qface/idl/listener.py index 6967666..4e9e720 100644 --- a/qface/idl/listener.py +++ b/qface/idl/listener.py @@ -7,6 +7,7 @@ from .domain import * from antlr4 import ParserRuleContext import yaml import click +from .profile import get_features, EProfile, EFeature try: from yaml import CSafeLoader as Loader, CDumper as Dumper @@ -20,15 +21,28 @@ log = logging.getLogger(__name__) contextMap = {} -class DomainListener(TListener): +class QFaceListener(TListener): + def __init__(self, system, profile=EProfile.BASIC): + super(QFaceListener, self).__init__() + self.lang_features = get_features(profile) + self.system = system or System() # type:System + + def is_supported(feature, report=True): + if feature not in self.lang_features and report: + click.secho('Unsuported language feature: {}'.format(EFeature.IMPORT), fg='red') + return False + return True + + + +class DomainListener(QFaceListener): """The domain listener is called by the parser to fill the domain data struture. As a result a system is passed back""" - def __init__(self, system): - super(DomainListener, self).__init__() + def __init__(self, system, profile=EProfile.BASIC): + super(QFaceListener, self).__init__(system, profile) contextMap.clear() - self.system = system or System() # type:System self.module = None # type:Module self.interface = None # type:Interface self.struct = None # type:Struct @@ -236,9 +250,10 @@ class DomainListener(TListener): def enterImportSymbol(self, ctx: TParser.ImportSymbolContext): assert self.module - name = ctx.name.text - version = ctx.version.text - self.module._importMap[name] = '{0} {1}'.format(name, version) + if self.is_supported(EFeature.IMPORT): + name = ctx.name.text + version = ctx.version.text + self.module._importMap[name] = '{0} {1}'.format(name, version) def exitImportSymbol(self, ctx: TParser.ImportSymbolContext): pass diff --git a/qface/idl/profile.py b/qface/idl/profile.py index 4b376c9..eeade91 100644 --- a/qface/idl/profile.py +++ b/qface/idl/profile.py @@ -1,36 +1,46 @@ # Copyright (c) Pelagicore AB 2016 +""" +A profile is a set of features describing a qface language profile. +The language profile tells the parser which language aspects are +supported for the particular choosen profile. + +from profile import get_features, EProfile, EFeature + +features = get_features(EProfile.ADVANCED) + +if EFeature.CONST_OPERATION in features: + # parse this aspect of the language + +""" from enum import Enum class EFeature(Enum): - CONST_PROPERTY = 'const_property' + CONST_OPERATION = 'const_operation' EXTEND_INTERFACE = 'extend_interface' + IMPORT = 'import' + MAPS = 'maps' class EProfile(Enum): BASIC = 'basic' ADVANCED = 'advanced' - ALL = 'advanced' - - -class Profile: - def __init__(self, features=set()): - self.features = features - - @staticmethod - def get_profile(cls, name): - if name is EProfile.BASIC: - return Profile(features=[ - ]) - if name is EProfile.ADVANCED: - return Profile(features=[ - EFeature.CONST_PROPERTY, - EFeature.EXTEND_INTERFACE - ]) - if name is EProfile.ALL: - return Profile(features=[ - ]) - return [] + FULL = 'full' + + +_profiles = { + EProfile.BASIC: set(), + EProfile.ADVANCED: set([ + EFeature.CONST_PROPERTY, + EFeature.EXTEND_INTERFACE, + EFeature.IMPORT, + EFeature.MAPS + ]), + EProfile.ALL: set(EFeature) +} + +def get_features(name): + return _profiles.get(name, set()) |