mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-12-28 01:29:46 +00:00
Thunderclock: Tweak DOS/BASIC handling of colons
This is ugly, but you should see what real BASIC/DOS do under the hood.
This commit is contained in:
parent
d727640ef4
commit
d7ebf753db
7
basic.js
7
basic.js
@ -335,9 +335,10 @@ this.basic = (function() {
|
||||
var regexWhitespace = /^[ \t]+/,
|
||||
regexQuotedString = /^"([^"]*?)(?:"|(?=\n|\r|$))/,
|
||||
regexUnquotedString = /^[^:,\r\n]*/,
|
||||
regexUnquotedStringIgnoreColons = /^[^,\r\n]*/,
|
||||
regexComma = /^,/;
|
||||
|
||||
return function parseDataInput(stream, items) {
|
||||
return function parseDataInput(stream, items, ignoreColons) {
|
||||
|
||||
do {
|
||||
stream.match(regexWhitespace);
|
||||
@ -345,7 +346,7 @@ this.basic = (function() {
|
||||
if (stream.match(regexQuotedString)) {
|
||||
// quoted string
|
||||
items.push(stream.lastMatch[1]);
|
||||
} else if (stream.match(regexUnquotedString)) {
|
||||
} else if (stream.match(ignoreColons ? regexUnquotedStringIgnoreColons : regexUnquotedString)) {
|
||||
// unquoted string
|
||||
items.push(stream.lastMatch[0]);
|
||||
}
|
||||
@ -760,7 +761,7 @@ this.basic = (function() {
|
||||
var parts = [],
|
||||
stream = new Stream(entry);
|
||||
|
||||
parseDataInput(stream, parts);
|
||||
parseDataInput(stream, parts, entry.ignoreColons);
|
||||
|
||||
while (varlist.length && parts.length) {
|
||||
try {
|
||||
|
13
dos.js
13
dos.js
@ -442,6 +442,9 @@ function DOS(tty) {
|
||||
tty.writeString(prompt + string + "\r");
|
||||
}
|
||||
|
||||
// Suppress BASIC parsing of colons
|
||||
string = Object.assign(new String(string), {ignoreColons: true});
|
||||
|
||||
// Non-blocking return
|
||||
setTimeout(function() { callback(string); }, 0);
|
||||
} else {
|
||||
@ -527,7 +530,7 @@ function DOS(tty) {
|
||||
var MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
|
||||
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
||||
function spad2(s) {
|
||||
return ('00' + String(s)).slice(-2);
|
||||
return (' ' + String(s)).slice(-2);
|
||||
}
|
||||
function zpad2(s) {
|
||||
return ('00' + String(s)).slice(-2);
|
||||
@ -544,7 +547,7 @@ function DOS(tty) {
|
||||
clockbuf =
|
||||
DAYS[now.getDay()] + ' ' +
|
||||
MONTHS[now.getMonth()] + ' ' +
|
||||
now.getDate() + ' ' +
|
||||
spad2(now.getDate()) + ' ' +
|
||||
spad2((now.getHours() === 0 ? 12 : now.getHours() > 12 ? now.getHours() - 12 : now.getHours())) + ':' +
|
||||
zpad2(now.getMinutes()) + ':' +
|
||||
zpad2(now.getSeconds()) + ' ' +
|
||||
@ -555,7 +558,7 @@ function DOS(tty) {
|
||||
clockbuf =
|
||||
DAYS[now.getDay()] + ' ' +
|
||||
MONTHS[now.getMonth()] + ' ' +
|
||||
now.getDate() + ' ' +
|
||||
spad2(now.getDate()) + ' ' +
|
||||
spad2(now.getHours()) + ':' +
|
||||
zpad2(now.getMinutes()) + ':' +
|
||||
zpad2(now.getSeconds()) + ' ' +
|
||||
@ -587,6 +590,10 @@ function DOS(tty) {
|
||||
tty.writeString(prompt); // TODO: Correct? Newline?
|
||||
var tmp = clockbuf;
|
||||
clockbuf = '';
|
||||
|
||||
// Suppress BASIC parsing of colons
|
||||
tmp = Object.assign(new String(tmp), {ignoreColons: true});
|
||||
|
||||
setTimeout(function() { callback(tmp); }, 0);
|
||||
}
|
||||
function clock_readChar(callback) {
|
||||
|
@ -94,7 +94,7 @@ sample.onelinetrain One Liner Train (Chris ten Den)
|
||||
sample.piglatin Pig Latin Translator (Gregg Buntin)
|
||||
sample.nuclear Nuclear Power Plant (Stephen R. Berggren c/o Kevin Riggle)
|
||||
sample.factors Prime Factors (Cristiano Trabuio)
|
||||
sample.thunderclock Thunderclock (incomplete)
|
||||
sample.thunderclock Thunderclock
|
||||
|
||||
# ____________________________________________
|
||||
# Traveller RPG Utilities
|
||||
|
@ -19,3 +19,22 @@
|
||||
163 PRINT "Hours: ";HR
|
||||
164 PRINT "Minutes: ";MN
|
||||
165 PRINT "Seconds: ";SEC
|
||||
166 PRINT
|
||||
|
||||
210 PRINT "12-Hour Format"
|
||||
220 PRINT CHR$(4);"PR#4"
|
||||
230 PRINT CHR$(4);"IN#4"
|
||||
240 INPUT ">";T$
|
||||
250 PRINT CHR$(4);"PR#0"
|
||||
260 PRINT CHR$(4);"IN#0"
|
||||
270 PRINT T$
|
||||
280 PRINT
|
||||
|
||||
310 PRINT "24-Hour Format"
|
||||
320 PRINT CHR$(4);"PR#4"
|
||||
330 PRINT CHR$(4);"IN#4"
|
||||
340 INPUT "<";T$
|
||||
350 PRINT CHR$(4);"PR#0"
|
||||
360 PRINT CHR$(4);"IN#0"
|
||||
370 PRINT T$
|
||||
380 PRINT
|
||||
|
Loading…
Reference in New Issue
Block a user