Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added loading utility modules into __Utilities so that they are avail…

…able to ometajs files

Added utility info to --help
Added example-utilities.js to node_modules
  • Loading branch information...
commit 0909427d2b736dc34510e7459adfb007a2af77d0 1 parent e30be20
@tristanls authored
View
53 bin/ometajsnode
@@ -8,25 +8,34 @@ var usage = "Usage: ometajsnode <-C|-I|-P> <-g|--grammar grammar_file> [options]
var help1 = [
usage,
"",
- "Operational Modes: Only one mode is supported at a time, last mode specified will be used",
- " -C Compile the program using provided grammar and compiler",
- " -I Interpret the program using provided grammar and interpreter",
- " -P Parse the program only, using the provided grammar",
+ "Operational Modes: Only one mode is supported at a time, last mode specified will be used",
+ " -C Compile the program using provided grammar and compiler",
+ " -I Interpret the program using provided grammar and interpreter",
+ " -P Parse the program only, using the provided grammar",
""
].join( '\n' );
var help2 = [
"Options:",
- " -c, --compiler <file> Specifies compiler file to use",
- " --compiler-root <root> Name of the root expression in the compiler grammar",
- " --debug Run in debug mode",
- " -g, --grammar <file> Specifies grammar file to use",
- " -h, --help Displays this information",
- " -i, --interpreter <file> Specifies interpreter file to use",
- " --interpreter-root <root> Name of the root expression in the interpreter grammar",
- " -o, --output <file> Place the output into file",
- " --parser-root <root> Name of the root expression in the parser grammar",
- " --verbose Run in verbose mode",
- " --version Version"
+ " -c, --compiler <file> Specifies compiler file to use",
+ " --compiler-root <root> Name of the root expression in the compiler grammar",
+ " --debug Run in debug mode",
+ " -g, --grammar <file> Specifies grammar file to use",
+ " -h, --help Displays this information",
+ " -i, --interpreter <file> Specifies interpreter file to use",
+ " --interpreter-root <root> Name of the root expression in the interpreter grammar",
+ " -o, --output <file> Place the output into file",
+ " --parser-root <root> Name of the root expression in the parser grammar",
+ ""
+].join( '\n' );
+var help3 = [
+ " -u, --utility <module_file[,module_file]> Specifies a list of modules that will be available for access by ometajs files via __Utilities",
+ " Modules used as untilities must export 'utilityName' property to be read",
+ " For example, my make-unique-ident module could look like:",
+ " exports.untilityName = 'make-unique-ident'",
+ " Then any ometajs file could use it via __Utilities['make-unique-ident']",
+ " --verbose Run in verbose mode",
+ " --version Version",
+ ""
].join( '\n' );
var ometajsnode = require( 'ometajsnode' );
@@ -69,7 +78,8 @@ while ( arg = argv.shift() ) {
case 'help':
case 'h':
process.stdout.write( help1 );
- process.stdout.write( help2 + '\n' );
+ process.stdout.write( help2 );
+ process.stdout.write( help3 + '\n' );
process.exit( 0 );
break;
case 'I':
@@ -92,6 +102,11 @@ while ( arg = argv.shift() ) {
case 'parser-root':
options.rootParserExpression = argv.shift();
break;
+ case 'utility':
+ case 'u':
+ options.utilities = argv.shift();
+ options.utilities = options.utilities.split( ',' );
+ break;
case 'verbose':
options.loglyMode = 'verbose';
logly.mode('verbose');
@@ -147,7 +162,7 @@ if ( 'compile' == options.mode ) {
ometajsnode.execute( 'compile', options.loglyMode, options.grammar,
options.input, options.compiler, undefined, options.output,
options.rootParserExpression, options.rootInterpreterExpression,
- options.rootCompilerExpression);
+ options.rootCompilerExpression, options.utilities );
} else if ( 'interpret' == options.mode ) {
@@ -160,7 +175,7 @@ if ( 'compile' == options.mode ) {
ometajsnode.execute( 'interpret', options.loglyMode, options.grammar,
options.input, undefined, options.interpreter, options.output,
options.rootParserExpression, options.rootInterpreterExpression,
- options.rootCompilerExpression);
+ options.rootCompilerExpression, options.utilities);
} else if ( 'parse' == options.mode ) {
@@ -173,5 +188,5 @@ if ( 'compile' == options.mode ) {
ometajsnode.execute( 'parse', options.loglyMode, options.grammar,
options.input, undefined, undefined, options.output,
options.rootParserExpression, options.rootInterpreterExpression,
- options.rootCompilerExpression );
+ options.rootCompilerExpression, options.utilities );
}
View
2  node_modules/example-utilities.js
@@ -0,0 +1,2 @@
+exports.version = "1.0.0";
+exports.utilityName = 'utilities';
View
44 node_modules/ometajsnode/ometajsnode.js
@@ -1,4 +1,4 @@
-exports.version = "0.1.0";
+exports.version = "0.2.0";
//capture module context
var module = this;
@@ -16,11 +16,12 @@ var mode,
outputFileName,
rootParserExpression,
rootInterpreterExpression,
- rootCompilerExpression;
+ rootCompilerExpression,
+ utilities;
var execute = function( mode, loglyMode, grammarFileName, inputFileNames,
compilerFileName, interpreterFileName, outputFileName, rootParserExpression,
- rootInterpreterExpression, rootCompilerExpression) {
+ rootInterpreterExpression, rootCompilerExpression, utilities ) {
module.mode = mode;
module.loglyMode = loglyMode;
module.grammarFileName = grammarFileName;
@@ -31,11 +32,38 @@ var execute = function( mode, loglyMode, grammarFileName, inputFileNames,
module.rootParserExpression = rootParserExpression;
module.rootInterpreterExpression = rootInterpreterExpression;
module.rootCompilerExpression = rootCompilerExpression;
+ module.utilities = utilities;
logly.mode( loglyMode );
logly.verbose( 'starting execution in ' + mode + ' mode...' );
+ __Utilities = {};
+ if ( utilities ) {
+ logly.verbose( 'loading utilities...' );
+
+ for ( var i = 0; i < utilities.length; i++ ) {
+ var temp = null;
+ try {
+ temp = require( utilities[ i ] );
+ } catch ( err ) {
+ logly.error( err.message );
+ process.exit( 1 );
+ }
+ if ( temp ) {
+ if ( !temp.utilityName ) {
+ logly.error( "module '" + utilities[ i ] + "' does not export 'utilityName', aborting..." );
+ process.exit( 1 );
+ }
+ __Utilities[ temp.utilityName ] = temp;
+ logly.debug( "loaded utility '" + utilities[ i ] + "' as __Utilities[ '" + temp.utilityName + "' ]" );
+ }
+ }
+ logly.verbose( "utilities loaded" );
+ } else {
+ logly.verbose( "no utilities to load" );
+ }
+
// read grammar string from file
logly.verbose( "reading grammar file..." );
fs.readFile( grammarFileName, 'utf8', grammarFileReadComplete);
@@ -83,9 +111,19 @@ var grammarFileReadComplete = function( err, grammarString ) {
} else if ( module.mode == 'compile' ) {
logly.error( 'compile mode not yet implemented' );
process.exit( 1 );
+
+ startCompiling( parserString, module.outputFileName,
+ module.compilerFileName, module.inputFileNames,
+ module.rootParserExpression, module.rootCompilerExpression );
}
} ;
+var startCompiling = function( parserString, outputFileName,
+ compilerFileName, inputFileNames, rootParserExpression,
+ rootCompilerExpression ) {
+
+};
+
var startInterpreting = function( parserString, outputFileName,
interpreterFileName, inputFileNames, rootParserExpression,
rootInterpreterExpression ) {
Please sign in to comment.
Something went wrong with that request. Please try again.