Add pause command

This commit is contained in:
Robert Miles 2020-06-30 00:13:24 -04:00
parent dab5f5e0b9
commit f61d38cc1a
2 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# ChooseScript Specification v0.1.2
# ChooseScript Specification v0.1.3
## Abstract
@ -48,6 +48,7 @@ The following literal stems are commands. They MUST NOT be used as targets.
- `input` - see section 2.4.1
- `testequals` - see section 2.5
- `check` - see section 2.5.1
- `pause` - see section 2.6
## 2. Commands
@ -113,6 +114,11 @@ An undefined variable MUST fail all comparisons.
A shorthand for `testequals <STEM> true`. If the variable represented by the
argument stem is not a boolean value, an error MUST be thrown.
### 2.6. `pause [<NUMBER>]`
Pause until user presses enter on their keyboard. Alternatively, pause for a
number of seconds defined by the argument number.
## 3. Implementation details
The following are details of the implementation. These are meant to be

View File

@ -1,6 +1,6 @@
from sly import Lexer as SlyLexer
commands = ["goto","print","choose","input","set","testequals","check","beq","bne"]
commands = ["goto","print","choose","input","set","testequals","check","beq","bne","pause"]
class Lexer(SlyLexer):
tokens = { STEM, COMMAND, TARGET, STRING, NUMBER, BOOLEAN }
@ -49,6 +49,7 @@ import sys
def caller_id():
return sys._getframe(2).f_code.co_name
import time
class Evaluator:
def __init__(self): pass
def run(self,prog):
@ -165,6 +166,11 @@ class Evaluator:
assert target.value in self.targets, f"Invalid branch target {target.value} at line {target.lineno}!"
if self.flag: return
self.pos = self.targets[target.value]
def command_pause(self):
if self.peek().type=="NUMBER":
time.sleep(self.next("NUMBER").value)
else:
input("Press enter to continue.")
if __name__=="__main__":
_, file = sys.argv