-
As far as I can tell, if one has a statement like
and would like to break the line in the second condition (I'm a bit of an 80-character nut so I can have two windows of code side-by-side on my screen, with both easily readable), one is just out of luck. In regular javascript code, I would switch from
presuming I knew x could never really be "[ToBeContinued" followed by three other characters, a "]", a newline, and several spaces. But right now this fails to parse. Alternatively in my use case, since I am just listing different options to be handled by the same code, some way of at least trivially falling through would also suffice. For example, condition specifications with no code in between could just be interpreted as a disjunction all handled by the same code following the last condition. If you actually wanted empty code for one of the cases (the current behavior of a condition specification immediately followed by another) you'd just need to insert some kind of null statement, like a semicolon on a line by itself, which Civet currently allows. Note this sort of null fallthrough would be a much smaller change than a general ability to fall through as suggested in #661. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You could use switch x
/ordinary.*/
console.log 'Things look normal'
///many|different|unusual|possibilities|listed|
here|because|all|are|handled|similarly///
console.log 'Yellow alert!'
Riffing on your last paragraph, another feature that might help you would be listing patterns over multiple lines via a trailing comma, like this: switch x
/ordinary.*/
console.log 'Things look normal'
/many/, /different/, /unusual/, /possibilities/, /listed/,
/here/, /because/, /all/, /are/, /handled/, /similarly/
console.log 'Yellow alert!' This doesn't work yet but should be an easy addition. |
Beta Was this translation helpful? Give feedback.
-
Dunno why it didn't occur to me that I could use a triple-slash regexp. That fits my bill just fine. Feel free to close this issue, or take it as a suggestion to put a triple-slash example in the "Pattern Matching" section of the Reference page, or move it to a Discussion as a Q&A for some other person who suffers the same mental block. |
Beta Was this translation helpful? Give feedback.
You could use
///
, which seems to work already:///
is what I generally gravitate to when I have complex regexes, but note that it eats whitespace, which is nice for formatting regexes (in particular line breaks and indentation are ignored), but it might mean you need to modify your regex a bit.Riffing on your last paragraph, another feature that might help you would be listing patterns over multiple lines via a trailing comma, like this: