defano / wyldcard

A clone of Apple's HyperCard and HyperTalk scripting language.
https://github.com/defano/wyldcard/wiki
MIT License
117 stars 12 forks source link

Is "milliseconds" part of the grammar/TimeUnit class/enum? #68

Closed Jimw338 closed 5 years ago

Jimw338 commented 5 years ago

I successfully added "milliseconds" to the TimeUnit, having to modify 4 files (HyperTalkBaseVisitor, HyperTalkParse,HyperTalkVisitor, and HyperTalkTreeVisitor) and the grammar of course to do it.

It works, although I noticed that even though MILLISECONDS is not part of the TimeUnit enum, it is used in the PartMover, PartResizer, WyldCardPeriodicMessageManager, and Throttle files. How does that work?

Everything else was auto-generated in the HyperTalkParser and HyperTalkVisitor classes when I recompiled. The Parser class looks at least partly like an enormouse[Dragging] [pun] FSM) (*)

() True, I don't think there is actually a "mouseDragging*" handler, but it was needed for the pun.

(I guess it would be invoked during the drag, and then mouseDrag only called only at the end - except that's not "canon". Perhaps a "mouseDragging" handler during the drag, "mouseDragBegin" at the very beginning (button down and moved some small distance away), "longPressBegan" (mouse down and some small time), and finally a "mouseDragFinished" at the end of a drag.)

The visit function in HyperTalkTreeVisitor:

@Override public Object visitMillisecondsTimeUnit(HyperTalkParser.MillisecondsTimeUnitContext ctx) { return TimeUnit.MILLISECONDS; }

If I leave this out, it breaks - it won't even close the script window, even if there's nothing in the script itself. So I assume that the HyperTalkParse sort of "continually scans" all the rules in the Visitor class, and so breaks when it can't find the proper functions in the parser classes.

How are string literals (quoted) parsed? Would it be possible to make it so that an unquoted literal that was the last item on a line after a "put" statement would be interpreted correctly? Thus the code

put "done"
put "the quick brown fox"

and the code,

put done
put the quick brown fox

would operate the same? This of course in non-canon.

("Premiering next year - "Hypercard: The Film.." :). Actually, that might not actually be a bad title for a history of how Apple invented/popularized the GUI interface, and with HC laid the groundwork (maybe) for Visual Basic and Visual Basic Studio. "Applescript Studio" was their "answer" to finally having a WYSIWYG editor - but I guess it was too little too late.)

defano commented 5 years ago

Surprised that leaving out a tree visitor method would produce the behavior you describe, especially with an empty script (but can't say I've tried). Every character you type into the script window causes the parser to run in the background so as to provide the live syntax checking feature. The script is considered malformed if the parser throws an exception (which would likely occur if you forget to override a tree visitor method).

TimeUnit is confusing because there are actually two different TimeUnit enumerations being used: the one of my invention (com.defano.hypertalk.ast.model.TimeUnit), and Java's built-in one (java.util.concurrent.TimeUnit). I think I created mine to introduce HC's concept of ticks.

The unquoted string literals in WyldCard are implemented in the public Value getVariable(String symbol) method of ExecutionContext. In your example, the done in put done is parsed as a symbol (variable). When no value has been put into that variable, the symbol is resolved to its own name.

Trying to support multi-token unquoted literals is certainly possible, but would require a huge amount of parser gymnastics and a context sensitive evaluation of the argument passed to put. (And probably a bunch of weird cases where the expected behavior is not obvious to script author.)