nirum-lang / nirum

Nirum: IDL compiler and RPC/distributed object framework for microservices
https://nirum.org/
GNU General Public License v3.0
121 stars 27 forks source link

Constraints for text unboxed type #307

Open kanghyojun opened 6 years ago

kanghyojun commented 6 years ago
@regexp-constraint("[a-zA-Z]+")
unboxed alpha (text);

As https://github.com/nirum-lang/nirum/issues/206 suggested, it might be useful if text is validated by the regular expression that gives in an annotation.

Alpha('1234') # error
Alpha("abcABC') # it works
kanghyojun commented 6 years ago

@dahlia @Kroisse Have you had any suggestions?

dahlia commented 6 years ago

If we use regular expressions we should choose a standard (e.g., POSIX Extended Regular Expression) for it to guarantee compatibility between target languages.

kanghyojun commented 6 years ago

POSIX Extended Regular Expression sounds good to me. Should we validate regular expression in an annotation when .nrm file is compiled?

kanghyojun commented 6 years ago

I think that we can use regex module which supports POSIX regular expression.

dahlia commented 6 years ago

Should we validate regular expression in an annotation when .nrm file is compiled?

If we want we can do by trying to parse a pattern using Text.Regex.TDFA.ReadRegex.parseRegex function.

kanghyojun commented 6 years ago

Decide to use re2 on Python.