nirum icon indicating copy to clipboard operation
nirum copied to clipboard

Constraints for text unboxed type

Open kanghyojun opened this issue 7 years ago • 6 comments

@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 avatar Aug 15 '18 07:08 kanghyojun

@dahlia @Kroisse Have you had any suggestions?

kanghyojun avatar Aug 15 '18 07:08 kanghyojun

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

dahlia avatar Aug 15 '18 07:08 dahlia

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

kanghyojun avatar Aug 15 '18 07:08 kanghyojun

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

kanghyojun avatar Aug 15 '18 07:08 kanghyojun

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.

dahlia avatar Aug 15 '18 07:08 dahlia

Decide to use re2 on Python.

kanghyojun avatar Aug 15 '18 08:08 kanghyojun