Documented and cleaned up parser a bit so I have an easier time circling back to this, refactored splash.js to be properly namespaced and handle window/stage resizing
This commit is contained in:
parent
7ba03595eb
commit
91bf367d80
2 changed files with 56 additions and 22 deletions
|
|
@ -4,7 +4,7 @@
|
|||
* @Requires:
|
||||
* Node.js (Run latest for safety ;P)
|
||||
* line_reader.js (custom, supplied in libraries)
|
||||
* wrench.js (custom, supplied in libraries
|
||||
* wrench.js (custom, supplied in libraries)
|
||||
*
|
||||
* @Note: This is just a compiler/parser. Core Splash takes place inside the browser - no need
|
||||
* to muck around in DOM logic here when it's readily available over there. ;P
|
||||
|
|
@ -28,6 +28,10 @@ var sys = require('sys'),
|
|||
var determineAttrName = function(str) { return str.replace(whitespace, '').split(':')[0]; };
|
||||
var determineVal = function(str) { return str.replace(whitespace, '').split(':')[1]; };
|
||||
|
||||
/* Aptly, returns a variable type from parsing a string.
|
||||
*
|
||||
* e.g, given "verb b:", this will return "verb"
|
||||
*/
|
||||
var getType = function(str) {
|
||||
if(/verb/.test(str)) return "verb";
|
||||
|
||||
|
|
@ -45,7 +49,7 @@ exports.writeApp = function(text) {
|
|||
* one directory up from this file for execution.
|
||||
*/
|
||||
wrench.copyDirSyncRecursive(currPath + '/lib/app_base', currPath + '/' + appName);
|
||||
fs.writeFileSync(currPath + "/" + appName + "/scripts/compiled.js", "function main() { game_on(" + finalJSON + "); };", encoding="utf8");
|
||||
fs.writeFileSync(currPath + "/" + appName + "/scripts/compiled.js", "function main() { splash.game_on(" + finalJSON + "); };", encoding="utf8");
|
||||
};
|
||||
|
||||
/* In Splash, explanations are essentially variable declarations,
|
||||
|
|
@ -58,23 +62,30 @@ exports.writeApp = function(text) {
|
|||
* who: daniel
|
||||
* action: move
|
||||
* direction: left
|
||||
* done
|
||||
* end
|
||||
*
|
||||
* @Note: This parse is currently very "top down", and not as forgiving as it should be.
|
||||
*/
|
||||
while(expr.hasNextLine()) {
|
||||
var currLine = expr.getNextLine(),
|
||||
isBeginning = stripper.test(currLine);
|
||||
isBeginning = stripper.test(currLine); /* Tests to see if we make a declaration. */
|
||||
|
||||
if(creatingBlock || isBeginning) {
|
||||
creatingBlock = /end/.test(currLine) ? false : true;
|
||||
|
||||
/* type = verb/noun/etc
|
||||
* name = name of the variable (e.g, verb run, name = run)
|
||||
*/
|
||||
if(isBeginning) block["type"] = getType(currLine);
|
||||
if(isBeginning) block["name"] = currLine.replace(stripper, '').replace(whitespace, '');
|
||||
else block[determineAttrName(currLine)] = determineVal(currLine);
|
||||
|
||||
/* If this is false, we're done building up a new block/JSON structure, so we can
|
||||
* push it onto the stack for the browser to get down the road. We also reset the
|
||||
* block here, so subsequent operations have a blank slate to work with.
|
||||
*/
|
||||
if(!creatingBlock) {
|
||||
finalRep.push(JSON.stringify(block)); //this.parseExplain(block);
|
||||
finalRep.push(JSON.stringify(block));
|
||||
block = {};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue