|
22 | 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | 23 | # SOFTWARE. |
24 | 24 |
|
| 25 | +from __future__ import unicode_literals |
25 | 26 | import sys |
26 | 27 | import os |
27 | 28 | import re |
@@ -78,9 +79,16 @@ class RE(object): |
78 | 79 | RS_ERR_REPLY = "ERR: No Reply Found" |
79 | 80 |
|
80 | 81 |
|
81 | | -class RiveScript: |
| 82 | +class RiveScript(object): |
82 | 83 | """A RiveScript interpreter for Python 2 and 3.""" |
83 | 84 |
|
| 85 | + # Concatenation mode characters. |
| 86 | + _concat_modes = dict( |
| 87 | + none="", |
| 88 | + space=" ", |
| 89 | + newline="\n", |
| 90 | + ) |
| 91 | + |
84 | 92 | ############################################################################ |
85 | 93 | # Initialization and Utility Methods # |
86 | 94 | ############################################################################ |
@@ -220,6 +228,11 @@ def _parse(self, fname, code): |
220 | 228 | concnt = 0 # Condition counter |
221 | 229 | isThat = '' # Is a %Previous trigger |
222 | 230 |
|
| 231 | + # Local (file scoped) parser options. |
| 232 | + local_options = dict( |
| 233 | + concat="none", # Concat mode for ^Continue command |
| 234 | + ) |
| 235 | + |
223 | 236 | # Read each line. |
224 | 237 | for lp, line in enumerate(code): |
225 | 238 | lineno = lineno + 1 |
@@ -329,7 +342,9 @@ def _parse(self, fname, code): |
329 | 342 | # end of the current line. |
330 | 343 | if cmd != '^' and lookCmd != '%': |
331 | 344 | if lookCmd == '^': |
332 | | - line += lookahead |
| 345 | + line += self._concat_modes.get( |
| 346 | + local_options["concat"], "" |
| 347 | + ) + lookahead |
333 | 348 | else: |
334 | 349 | break |
335 | 350 |
|
@@ -372,7 +387,11 @@ def _parse(self, fname, code): |
372 | 387 | continue |
373 | 388 |
|
374 | 389 | # Handle the rest of the types. |
375 | | - if type == 'global': |
| 390 | + if type == 'local': |
| 391 | + # Local file-scoped parser options. |
| 392 | + self._say("\tSet parser option " + var + " = " + value) |
| 393 | + local_options[var] = value |
| 394 | + elif type == 'global': |
376 | 395 | # 'Global' variables |
377 | 396 | self._say("\tSet global " + var + " = " + value) |
378 | 397 |
|
|
0 commit comments