Replace |util.{puts,error}| by |console.{log,error}|

The |util.puts| and |util.error| functions are deprecated in Node.js
0.12.x.

Based on a pull request by Jan Stránský (@burningtree):

  https://github.com/pegjs/pegjs/pull/334
redux
David Majda 9 years ago
parent 4b154e177f
commit de1704f007

@ -2,9 +2,8 @@
"use strict"; "use strict";
var util = require("util"); var fs = require("fs");
var fs = require("fs"); var PEG = require("../lib/peg");
var PEG = require("../lib/peg");
var benchmarks = require("./benchmarks.js"); var benchmarks = require("./benchmarks.js");
var Runner = require("./runner.js")(PEG); var Runner = require("./runner.js")(PEG);
@ -35,21 +34,21 @@ function center(text, length) {
} }
function writeTableHeader() { function writeTableHeader() {
util.puts("┌─────────────────────────────────────┬───────────┬────────────┬──────────────┐"); console.log("┌─────────────────────────────────────┬───────────┬────────────┬──────────────┐");
util.puts("│ Test │ Inp. size │ Avg. time │ Avg. speed │"); console.log("│ Test │ Inp. size │ Avg. time │ Avg. speed │");
} }
function writeHeading(heading) { function writeHeading(heading) {
util.puts("├─────────────────────────────────────┴───────────┴────────────┴──────────────┤"); console.log("├─────────────────────────────────────┴───────────┴────────────┴──────────────┤");
util.puts("│ " + center(heading, 75) + " │"); console.log("│ " + center(heading, 75) + " │");
util.puts("├─────────────────────────────────────┬───────────┬────────────┬──────────────┤"); console.log("├─────────────────────────────────────┬───────────┬────────────┬──────────────┤");
} }
function writeResult(title, inputSize, parseTime) { function writeResult(title, inputSize, parseTime) {
var KB = 1024; var KB = 1024;
var MS_IN_S = 1000; var MS_IN_S = 1000;
util.puts("│ " console.log("│ "
+ padRight(title, 35) + padRight(title, 35)
+ " │ " + " │ "
+ padLeft((inputSize / KB).toFixed(2), 6) + padLeft((inputSize / KB).toFixed(2), 6)
@ -62,25 +61,25 @@ function writeResult(title, inputSize, parseTime) {
} }
function writeSeparator() { function writeSeparator() {
util.puts("├─────────────────────────────────────┼───────────┼────────────┼──────────────┤"); console.log("├─────────────────────────────────────┼───────────┼────────────┼──────────────┤");
} }
function writeTableFooter() { function writeTableFooter() {
util.puts("└─────────────────────────────────────┴───────────┴────────────┴──────────────┘"); console.log("└─────────────────────────────────────┴───────────┴────────────┴──────────────┘");
} }
/* Helpers */ /* Helpers */
function printHelp() { function printHelp() {
util.puts("Usage: run [options]"); console.log("Usage: run [options]");
util.puts(""); console.log("");
util.puts("Runs PEG.js benchmark suite."); console.log("Runs PEG.js benchmark suite.");
util.puts(""); console.log("");
util.puts("Options:"); console.log("Options:");
util.puts(" -n, --run-count <n> number of runs (default: 10)"); console.log(" -n, --run-count <n> number of runs (default: 10)");
util.puts(" --cache make tested parsers cache results"); console.log(" --cache make tested parsers cache results");
util.puts(" -o, --optimize <goal> select optimization for speed or size (default:"); console.log(" -o, --optimize <goal> select optimization for speed or size (default:");
util.puts(" speed)"); console.log(" speed)");
} }
function exitSuccess() { function exitSuccess() {
@ -92,7 +91,7 @@ function exitFailure() {
} }
function abort(message) { function abort(message) {
util.error(message); console.error(message);
exitFailure(); exitFailure();
} }

@ -2,7 +2,6 @@
"use strict"; "use strict";
var util = require("util");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var PEG = require("../lib/peg"); var PEG = require("../lib/peg");
@ -10,39 +9,39 @@ var PEG = require("../lib/peg");
/* Helpers */ /* Helpers */
function printVersion() { function printVersion() {
util.puts("PEG.js " + PEG.VERSION); console.log("PEG.js " + PEG.VERSION);
} }
function printHelp() { function printHelp() {
util.puts("Usage: pegjs [options] [--] [<input_file>] [<output_file>]"); console.log("Usage: pegjs [options] [--] [<input_file>] [<output_file>]");
util.puts(""); console.log("");
util.puts("Generates a parser from the PEG grammar specified in the <input_file> and writes"); console.log("Generates a parser from the PEG grammar specified in the <input_file> and writes");
util.puts("it to the <output_file>."); console.log("it to the <output_file>.");
util.puts(""); console.log("");
util.puts("If the <output_file> is omitted, its name is generated by changing the"); console.log("If the <output_file> is omitted, its name is generated by changing the");
util.puts("<input_file> extension to \".js\". If both <input_file> and <output_file> are"); console.log("<input_file> extension to \".js\". If both <input_file> and <output_file> are");
util.puts("omitted, standard input and output are used."); console.log("omitted, standard input and output are used.");
util.puts(""); console.log("");
util.puts("Options:"); console.log("Options:");
util.puts(" -e, --export-var <variable> name of the variable where the parser"); console.log(" -e, --export-var <variable> name of the variable where the parser");
util.puts(" object will be stored (default:"); console.log(" object will be stored (default:");
util.puts(" \"module.exports\")"); console.log(" \"module.exports\")");
util.puts(" --cache make generated parser cache results"); console.log(" --cache make generated parser cache results");
util.puts(" --allowed-start-rules <rules> comma-separated list of rules the generated"); console.log(" --allowed-start-rules <rules> comma-separated list of rules the generated");
util.puts(" parser will be allowed to start parsing"); console.log(" parser will be allowed to start parsing");
util.puts(" from (default: the first rule in the"); console.log(" from (default: the first rule in the");
util.puts(" grammar)"); console.log(" grammar)");
util.puts(" -o, --optimize <goal> select optimization for speed or size"); console.log(" -o, --optimize <goal> select optimization for speed or size");
util.puts(" (default: speed)"); console.log(" (default: speed)");
util.puts(" --trace enable tracing in generated parser"); console.log(" --trace enable tracing in generated parser");
util.puts(" --plugin <plugin> use a specified plugin (can be specified"); console.log(" --plugin <plugin> use a specified plugin (can be specified");
util.puts(" multiple times)"); console.log(" multiple times)");
util.puts(" --extra-options <options> additional options (in JSON format) to pass"); console.log(" --extra-options <options> additional options (in JSON format) to pass");
util.puts(" to PEG.buildParser"); console.log(" to PEG.buildParser");
util.puts(" --extra-options-file <file> file with additional options (in JSON"); console.log(" --extra-options-file <file> file with additional options (in JSON");
util.puts(" format) to pass to PEG.buildParser"); console.log(" format) to pass to PEG.buildParser");
util.puts(" -v, --version print version information and exit"); console.log(" -v, --version print version information and exit");
util.puts(" -h, --help print help and exit"); console.log(" -h, --help print help and exit");
} }
function exitSuccess() { function exitSuccess() {
@ -54,7 +53,7 @@ function exitFailure() {
} }
function abort(message) { function abort(message) {
util.error(message); console.error(message);
exitFailure(); exitFailure();
} }

Loading…
Cancel
Save