-
Notifications
You must be signed in to change notification settings - Fork 10
String Functions
Regular expressions in PogoScript are currently implemented using back-ticks:
filename: replace `.*\.jpg$` '.png'
This is because forward-slashes can't be distinguished from divide operators, eg:
a / b / c
Is this a
divided by b
divided by c
, or a function a c
that takes a regular expression / b /
? Hard to tell. JavaScript can tell the difference because function arguments are always in parens, and are always after the function name.
Alternatively we could prefix the forward-slashes, say with an r
:
filename: replace r/.*\.jpg$/ '.png'
This appears to be a bit more conventional than back-ticks. But, we should be able to generalise the syntax, firstly by allowing different delimiters. Let's try {}
:
filename: replace r{.*\.jpg$} '.png'
Or, +
:
filename: replace r+.*\.jpg$+ '.png'
Not dissimilar to Ruby's %r{}
syntax.
And we could take it even further still by suggesting that r
is a function on the string argument '.*\.jpg$'
. The way we know is that there are no spaces between the r
and the string. So we could define other functions such as u
, to parse a URL:
get u"http://example.com/"
Which is equivalent to:
get (u "http://example.com/")
Not sure if that's confusing at all.
According to the documentation, you can have Closure Compiler add the sourceMappingURL to the bottom of the script with something like this:
--output_wrapper "%output%
//# sourceMappingURL=output.js.map"
being added to your call. Not that you cannot use "\n" here, and you need a newline literal. On a Linux shell this works just fine (if you're inside of quotes when you press enter, the command doesn't get executed).