uniform-team / Uniform-Validation-Language

A logic language to simplify and improve online form validation.
Apache License 2.0
1 stars 0 forks source link

Remove Quote from Regex #15

Closed dgp1130 closed 7 years ago

dgp1130 commented 8 years ago

Regular expressions are defined as /" "/. This was meant to emulate the JavaScript format / /, but the quotes were added to make parsing easier and reduce development time in the early stage. We should remove these quotes so it correctly matches JavaScript syntax as we were originally intending.

dgp1130 commented 7 years ago

Also should add support for the g, w, and any other flags JavaScript regular expressions support.

dgp1130 commented 7 years ago

Redefined regexes as / /, removing the quotes. Tokenizing this was a little tricky, as the / character is quite overloaded. Ultimately, the lexer looks at the previous token to see if a regex can follow it. For instance, a regex can follow a comparator input matches /test/ but cannot follow an expression input /test/.

Regexes support 3 flags which are appended immediately after the closing slash. The i flag, sets the regex to ignore case (just like in JavaScript). The m flag sets the regex to allow multi-line matching (just like in JavaScript). The x flag forces the regex to match the ENTIRE input string (just like in grep). There were a few other flags JavaScript supports, but they maintain state between invocations, which doesn't really make sense in our language, so I left them out. The JavaScript u flag might be useful once we support Unicode, so I filed #60 to address that when we get to it.

I also took this opportunity to add support for escaped characters in strings. Now we can use \n, \t, etc. in strings. I also removed many extraneous tokens which weren't being used for anything anymore, such as selectors $("#test"), commas, and this.