Closed dgp1130 closed 7 years ago
Also should add support for the g, w, and any other flags JavaScript regular expressions support.
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
.
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.