From 10df6730e14353adc59e79726f615f83053f9ab0 Mon Sep 17 00:00:00 2001 From: Juergen Bocklage-Ryannel Date: Thu, 6 Apr 2017 09:25:05 +0200 Subject: initial idea of a profile. Next would be to twek the listener --- qface/idl/profile.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 qface/idl/profile.py diff --git a/qface/idl/profile.py b/qface/idl/profile.py new file mode 100644 index 0000000..4b376c9 --- /dev/null +++ b/qface/idl/profile.py @@ -0,0 +1,36 @@ +# Copyright (c) Pelagicore AB 2016 + +from enum import Enum + + +class EFeature(Enum): + CONST_PROPERTY = 'const_property' + EXTEND_INTERFACE = 'extend_interface' + + +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 [] + + -- cgit v1.2.3 From c7b805476b038a0f60257b5ddfb8ebfc065bf62f Mon Sep 17 00:00:00 2001 From: Juergen Bocklage-Ryannel Date: Wed, 7 Mar 2018 18:30:21 +0100 Subject: Start to use the qface language profile --- qface/idl/listener.py | 29 ++++++++++++++++++++------- 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 fc5781a..feeb8c9 100644 --- a/qface/idl/listener.py +++ b/qface/idl/listener.py @@ -8,6 +8,7 @@ from .domain import * from antlr4 import ParserRuleContext import yaml import click +from .profile import get_features, EProfile, EFeature try: from yaml import CLoader as Loader, CDumper as Dumper @@ -21,15 +22,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 @@ -218,9 +232,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()) -- cgit v1.2.3