Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom type mapping #24

Open
dahlia opened this issue Jul 19, 2016 · 1 comment
Open

Custom type mapping #24

dahlia opened this issue Jul 19, 2016 · 1 comment
Labels
cmp:compiler Component: Compiler backend (e.g., annotation processors, code generators) cmp:transport Component: Transports target:python typ:enhance Type: Enhancement/new feature

Comments

@dahlia
Copy link
Member

dahlia commented Jul 19, 2016

Some types need to be mapped to the existing concrete type e.g.:

enum language = ko | en | ja | zh | ...;
enum country = KR | US | JP | TW | CN | HK | SG | ...;

@python-class("babel.core:Locale")
@python-serializer("Locale(Langage(python_value.language), Country(python_value.territory))")
@python-deserializer("babel.core.Locale.parse(nirum_value.language.value + '_' + nirum_value.territory.value)")
record locale (
    language language,
    country territory,
);
@dahlia dahlia added the typ:enhance Type: Enhancement/new feature label Jul 19, 2016
@dahlia dahlia added this to the Prepare to be public milestone Jul 19, 2016
@dahlia dahlia added cmp:compiler Component: Compiler backend (e.g., annotation processors, code generators) cmp:runtime Component: Target runtimes cmp:transport Component: Transports target:python and removed cmp:runtime Component: Target runtimes labels Aug 26, 2017
@dahlia
Copy link
Member Author

dahlia commented Dec 9, 2017

As annotations are more suitable for common things between target languages, it'd better to be configured in package.toml file, e.g.:

[targets.python.type_maps."i18n.locale"."locale"]
install_requires = ["babel"]
class = "babel.core:Locale"
serializer = """
Locale(Language(__python_value__.language),
       Country(__python_value__.territory))
"""
deserializer = """
babel.core.Locale.parse(
    __nirum_value__.language.value + '_' + __nirum_value__.territory.value
)
"""
// i18n/locale.nrm
record locale (
    language language,
    country territory,
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmp:compiler Component: Compiler backend (e.g., annotation processors, code generators) cmp:transport Component: Transports target:python typ:enhance Type: Enhancement/new feature
Projects
None yet
Development

No branches or pull requests

1 participant