Fossil SCM
Added more info on quoting rules in Tcl/TH1 to the th1.md doc
Commit
30e9ccd59dda6c2f332ef254f2c908fdd9e4b727facf5d4340a45378a8dc9334
Parent
40787f50119aced…
1 file changed
+32
+32
| --- www/th1.md | ||
| +++ www/th1.md | ||
| @@ -74,10 +74,42 @@ | ||
| 74 | 74 | If the expression is false and the third argument is `else`, then |
| 75 | 75 | the fourth argument is evaluated as a TH1 expression. |
| 76 | 76 | |
| 77 | 77 | So, you see, even though the example above spans five lines, it is really |
| 78 | 78 | just a single command. |
| 79 | + | |
| 80 | +All of this also explains the emphasis on *unescaped* characters above: | |
| 81 | +the curly braces `{ }` are string quoting characters in Tcl/TH1, not | |
| 82 | +block delimiters as in C. This is how we can have a command that extends | |
| 83 | +over multiple lines. It is also why the `else` keyword must be cuddled | |
| 84 | +up with the closing brace for the `if` clause's scriptlet. The following | |
| 85 | +is invalid Tcl/TH1: | |
| 86 | + | |
| 87 | + if {$current eq "dev"} { | |
| 88 | + puts "hello" | |
| 89 | + } | |
| 90 | + else { | |
| 91 | + puts "world" | |
| 92 | + } | |
| 93 | + | |
| 94 | +If you try to run this under either Tcl or TH1, the interpreter will | |
| 95 | +tell you that there is no `else` command, because with the newline on | |
| 96 | +the third line, you terminated the `if` command. | |
| 97 | + | |
| 98 | +Occasionally in Tcl/TH1 scripts, you may need to use a backslash at the | |
| 99 | +end of a line to allow a command to extend over multiple lines without | |
| 100 | +being considered two separate commands. Here's an example from one of | |
| 101 | +Fossil's test scripts: | |
| 102 | + | |
| 103 | + return [lindex [regexp -line -inline -nocase -- \ | |
| 104 | + {^uuid:\s+([0-9A-F]{40}) } [eval [getFossilCommand \ | |
| 105 | + $repository "" info trunk]]] end] | |
| 106 | + | |
| 107 | +Those backslashes allow the command to wrap nicely within a standard | |
| 108 | +terminal width while telling the interpreter to consider those three | |
| 109 | +lines as a single command. | |
| 110 | + | |
| 79 | 111 | |
| 80 | 112 | Summary of Core TH1 Commands |
| 81 | 113 | ---------------------------- |
| 82 | 114 | |
| 83 | 115 | The original Tcl language after when TH1 is modeled has a very rich |
| 84 | 116 |
| --- www/th1.md | |
| +++ www/th1.md | |
| @@ -74,10 +74,42 @@ | |
| 74 | If the expression is false and the third argument is `else`, then |
| 75 | the fourth argument is evaluated as a TH1 expression. |
| 76 | |
| 77 | So, you see, even though the example above spans five lines, it is really |
| 78 | just a single command. |
| 79 | |
| 80 | Summary of Core TH1 Commands |
| 81 | ---------------------------- |
| 82 | |
| 83 | The original Tcl language after when TH1 is modeled has a very rich |
| 84 |
| --- www/th1.md | |
| +++ www/th1.md | |
| @@ -74,10 +74,42 @@ | |
| 74 | If the expression is false and the third argument is `else`, then |
| 75 | the fourth argument is evaluated as a TH1 expression. |
| 76 | |
| 77 | So, you see, even though the example above spans five lines, it is really |
| 78 | just a single command. |
| 79 | |
| 80 | All of this also explains the emphasis on *unescaped* characters above: |
| 81 | the curly braces `{ }` are string quoting characters in Tcl/TH1, not |
| 82 | block delimiters as in C. This is how we can have a command that extends |
| 83 | over multiple lines. It is also why the `else` keyword must be cuddled |
| 84 | up with the closing brace for the `if` clause's scriptlet. The following |
| 85 | is invalid Tcl/TH1: |
| 86 | |
| 87 | if {$current eq "dev"} { |
| 88 | puts "hello" |
| 89 | } |
| 90 | else { |
| 91 | puts "world" |
| 92 | } |
| 93 | |
| 94 | If you try to run this under either Tcl or TH1, the interpreter will |
| 95 | tell you that there is no `else` command, because with the newline on |
| 96 | the third line, you terminated the `if` command. |
| 97 | |
| 98 | Occasionally in Tcl/TH1 scripts, you may need to use a backslash at the |
| 99 | end of a line to allow a command to extend over multiple lines without |
| 100 | being considered two separate commands. Here's an example from one of |
| 101 | Fossil's test scripts: |
| 102 | |
| 103 | return [lindex [regexp -line -inline -nocase -- \ |
| 104 | {^uuid:\s+([0-9A-F]{40}) } [eval [getFossilCommand \ |
| 105 | $repository "" info trunk]]] end] |
| 106 | |
| 107 | Those backslashes allow the command to wrap nicely within a standard |
| 108 | terminal width while telling the interpreter to consider those three |
| 109 | lines as a single command. |
| 110 | |
| 111 | |
| 112 | Summary of Core TH1 Commands |
| 113 | ---------------------------- |
| 114 | |
| 115 | The original Tcl language after when TH1 is modeled has a very rich |
| 116 |