<commit_before>let fs = require('fs');
let child_process = require('child_process');
let path = require('path');
let antlr4 = require('antlr4/index');
let ModelLexer = require('./ModelLexer').ModelLexer;
let ModelParser = require('./ModelParser').ModelParser;
import { codeGenerator } from './CodeGen';
import { preprocess } from './Helpers';
import 'babel-polyfill';
import { install } from 'source-map-support';
install();

let modelDirname;
let modelBasename;

exports.command = 'generate <model>';
exports.describe = 'generate model code';
exports.builder = {
  spec: {
    describe: 'filename of the I/O specification JSON file',
    type: 'string',
    alias: 's'
  },
  list: {
    describe: 'list model variables',
    type: 'boolean',
    alias: 'l'
  },
  refidtest: {
    describe: 'test reference ids',
    type: 'boolean',
    alias: 'r'
  },
};
exports.handler = argv => {
  // Parse input files and then hand data to the code generator.
  modelDirname = path.dirname(argv.model);
  modelBasename = path.basename(argv.model).replace(/\.mdl/i, '');
  let parseTree = parseModel(argv.model);
  let spec = parseSpec(argv.spec);
  let subscripts = parseSubscripts();
  let listMode = '';
  if (argv.list) {
    listMode = 'printVarList';
  }
  else if (argv.refidtest) {
    listMode = 'printRefIdTest';
  }
  let code = codeGenerator(parseTree, spec, subscripts, listMode).generate();
  // Print the generated code.
  if (!(argv.list || argv.refidtest)) {
    console.log(code);
  }
  process.exit(0);
}
function parseModel(modelFilename) {
  // Read the mdl file and return a parse tree.
  let input = preprocess(modelFilename);
  let chars = new antlr4.InputStream(input);
  let lexer = new ModelLexer(chars);
  let tokens = new antlr4.CommonTokenStream(lexer);
  let parser = new ModelParser(tokens);
  parser.buildParseTrees = true;<commit_msg>add code constant to emit preprocessor output and exit<commit_after>let fs = require('fs');
let child_process = require('child_process');
let path = require('path');
let antlr4 = require('antlr4/index');
let ModelLexer = require('./ModelLexer').ModelLexer;
let ModelParser = require('./ModelParser').ModelParser;
import { codeGenerator } from './CodeGen';
import { preprocess } from './Helpers';
import 'babel-polyfill';
import { install } from 'source-map-support';
install();

// Set PREPROCESS_ONLY to true to output the preprocessed model and quit.
const PREPROCESS_ONLY = false;

let modelDirname;
let modelBasename;

exports.command = 'generate <model>';
exports.describe = 'generate model code';
exports.builder = {
  spec: {
    describe: 'filename of the I/O specification JSON file',
    type: 'string',
    alias: 's'
  },
  list: {
    describe: 'list model variables',
    type: 'boolean',
    alias: 'l'
  },
  refidtest: {
    describe: 'test reference ids',
    type: 'boolean',
    alias: 'r'
  },
};
exports.handler = argv => {
  // Parse input files and then hand data to the code generator.
  modelDirname = path.dirname(argv.model);
  modelBasename = path.basename(argv.model).replace(/\.mdl/i, '');
  let parseTree = parseModel(argv.model);
  let spec = parseSpec(argv.spec);
  let subscripts = parseSubscripts();
  let listMode = '';
  if (argv.list) {
    listMode = 'printVarList';
  }
  else if (argv.refidtest) {
    listMode = 'printRefIdTest';
  }
  let code = codeGenerator(parseTree, spec, subscripts, listMode).generate();
  // Print the generated code.
  if (!(argv.list || argv.refidtest)) {
    console.log(code);
  }
  process.exit(0);
}
function parseModel(modelFilename) {
  // Read the mdl file and return a parse tree.
  let input = preprocess(modelFilename);
  if (PREPROCESS_ONLY) {
    console.log(input);
    process.exit();
  }
  let chars = new antlr4.InputStream(input);
  let lexer = new ModelLexer(chars);
  let tokens = new antlr4.CommonTokenStream(lexer);
  let parser = new ModelParser(tokens);
  parser.buildParseTrees = true;
{'fraction_non_alphanumeric': 0.1409344845099035, 'fraction_numerical': 0.0025393600812595226, 'mean_word_length': 3.979772439949431, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6365430', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1236, 'n_words': 345}