Skip to content

Commit

Permalink
Fix #92: Drop support for useless optimize option. There no reasons…
Browse files Browse the repository at this point in the history
… for use value other than `speed`
  • Loading branch information
Mingun committed May 4, 2021
1 parent 58ee201 commit 0427028
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 542 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Released: TBD
- Extends CI testing to `windows`, `macintosh`
- Increases node testing range to include `node 16`
- Adds an announcer to make the build process more readable
- Option for selection optimization mode removed as it has no significant effect on
majority of generated parsers and represents only academic interest mostly. You should
use minifiers to get smaller parsers. Option `optimize` is deleted from the `generate()`
options, flag `--optimize` is deleted from the CLI (you still can supply it, but the CLI
will issue a warning that the option is removed).
[@Mingun](https://github.com/peggyjs/peggy/pull/147)
- `location()`s now will have additional `source` property which value is taken
from the `options.grammarSource` property. That property can contain arbitrary
data,for example, path to the currently parsed file.
Expand Down
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Follow these steps to upgrade:
- Integrates both lexical and syntactical analysis
- Parsers have excellent error reporting out of the box
- Based on [parsing expression
grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism
grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism
— more powerful than traditional LL(_k_) and LR(_k_) parsers
- Usable [from your browser](https://peggyjs.org/online), from the command line,
or via JavaScript API
or via JavaScript API

## Getting Started

Expand Down Expand Up @@ -113,8 +113,6 @@ You can tweak the generated parser with several options:
pass to `peg.generate`
- `--format` — format of the generated parser: `amd`, `es`, `commonjs`, `globals`,
`umd` (default: `commonjs`)
- `--optimize` — selects between optimizing the generated parser for parsing
speed (`speed`) or code size (`size`) (default: `speed`)
- `--plugin` — makes Peggy use a specified plugin (can be specified multiple
times)
- `--trace` — makes the parser trace its progress
Expand Down Expand Up @@ -164,8 +162,6 @@ object to `peg.generate`. The following options are supported:
- `format` — format of the generated parser (`"amd"`, `"bare"`, `"commonjs"`,
`"es"`, `"globals"`, or `"umd"`); valid only when `output` is set to `"source"`
(default: `"bare"`)
- `optimize`— selects between optimizing the generated parser for parsing
speed (`"speed"`) or code size (`"size"`) (default: `"speed"`)
- `output` — if set to `"parser"`, the method will return generated parser
object; if set to `"source"`, it will return parser source code as a string
(default: `"parser"`)
Expand All @@ -182,7 +178,7 @@ Using the generated parser is simple — just call its `parse` method and pass a
input string as a parameter. The method will return a parse result (the exact
value depends on the grammar used to generate the parser) or throw an exception
if the input is invalid. The exception will contain `location`, `expected`,
`found`, and `message` properties with more details about the error.
`found`, and `message` properties with more details about the error.

```javascript
parser.parse("abba"); // returns ["a", "b", "b", "a"]
Expand Down Expand Up @@ -274,7 +270,7 @@ a _per-parse initializer_:
{
if (options.multiplier) {
input = "(" + input + ")*(" + options.multiplier + ")";
}
}
}
start
Expand Down Expand Up @@ -306,9 +302,9 @@ generated parser, it produces a _match result_, which is a JavaScript value. For
example:

- An expression matching a literal string produces a JavaScript string
containing matched text.
containing matched text.
- An expression matching repeated occurrence of some subexpression produces a
JavaScript array with all the matches.
JavaScript array with all the matches.

The match results propagate through the rules when the rule names are used in
expressions, up to the start rule. The generated parser returns start rule's
Expand Down Expand Up @@ -516,13 +512,13 @@ using the `text` function.
The code inside the action can also access location information using the
`location` function. It returns an object like this:

```javascript
{
```javascript
{
source: options.grammarSource,
start: { offset: 23, line: 5, column: 6 },
end: { offset: 25, line: 5, column: 8 }
}
```
start: { offset: 23, line: 5, column: 6 },
end: { offset: 25, line: 5, column: 8 }
}
```

The `start` property refers to the position at the beginning of the expression,
the `end` property refers to position after the end of the expression. The
Expand Down
1 change: 0 additions & 1 deletion benchmark/browser.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ $("#run").click(() => {
const runCount = parseInt($("#run-count").val(), 10);
const options = {
cache: $("#cache").is(":checked"),
optimize: $("#optimize").val(),
};

if (isNaN(runCount) || runCount <= 0) {
Expand Down
1 change: 0 additions & 1 deletion benchmark/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ a, a:visited { color: #3d586c; }
}
#options #run-count { width: 3em; }
#options #cache { margin-left: 2em; }
#options label[for=optimize] { margin-left: 2em; }
#options #run { float:right; width: 5em; }
5 changes: 0 additions & 5 deletions benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ <h1>Peggy Benchmark Suite</h1>
<input type="text" id="run-count" value="10"> times
<input type="checkbox" id="cache">
<label for="cache">Use results cache</label>
<label for="optimize">Optimize:</label>
<select id="optimize">
<option value="speed">Speed</option>
<option value="size">Size</option>
</select>
<input type="button" id="run" value="Run">
</div>

Expand Down
3 changes: 1 addition & 2 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ $("#run").click(() => {

const runCount = parseInt($("#run-count").val(), 10);
const options = {
cache: $("#cache").is(":checked"),
optimize: $("#optimize").val()
cache: $("#cache").is(":checked")
};

if (isNaN(runCount) || runCount <= 0) {
Expand Down
15 changes: 0 additions & 15 deletions benchmark/run_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ function printHelp() {
console.log("Options:");
console.log(" -n, --run-count <n> number of runs (default: 10)");
console.log(" --cache make tested parsers cache results");
console.log(" -o, --optimize <goal> select optimization for speed or size (default:");
console.log(" speed)");
}

function exitSuccess() {
Expand Down Expand Up @@ -113,7 +111,6 @@ function nextArg() {

const options = {
cache: false,
optimize: "speed"
};

let runCount = 10;
Expand All @@ -136,18 +133,6 @@ while (args.length > 0 && isOption(args[0])) {
options.cache = true;
break;

case "-o":
case "--optimize":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -o/--optimize option.");
}
if (args[0] !== "speed" && args[0] !== "size") {
abort("Optimization goal must be either \"speed\" or \"size\".");
}
options.optimize = args[0];
break;

case "-h":
case "--help":
printHelp();
Expand Down
13 changes: 3 additions & 10 deletions bin/peggy
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ function printHelp() {
console.log(" --format <format> format of the generated parser: amd,");
console.log(" commonjs, globals, umd (default: commonjs)");
console.log(" -h, --help print help and exit");
console.log(" -O, --optimize <goal> select optimization for speed or size");
console.log(" (default: speed)");
console.log(" -o, --output <file> output file");
console.log(" --plugin <plugin> use a specified plugin (can be specified");
console.log(" multiple times)");
Expand Down Expand Up @@ -112,7 +110,6 @@ const options = {
dependencies: {},
exportVar: null,
format: "commonjs",
optimize: "speed",
output: "source",
plugins: [],
trace: false
Expand Down Expand Up @@ -203,13 +200,9 @@ while (args.length > 0 && isOption(args[0])) {
case "-O":
case "--optimize":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -O/--optimize option.");
}
if (args[0] !== "speed" && args[0] !== "size") {
abort("Optimization goal must be either \"speed\" or \"size\".");
}
options.optimize = args[0];
console.error("Option --optimize is deprecated from 1.2.0 and has no effect anymore.");
console.error("It will be deleted in 2.0.");
console.error("Parser will be generated in the former \"speed\" mode.");
break;

case "-o":
Expand Down
1 change: 0 additions & 1 deletion docs/css/benchmark.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ a, a:visited { color: #3d586c; }
}
#options #run-count { width: 3em; }
#options #cache { margin-left: 2em; }
#options label[for=optimize] { margin-left: 2em; }
#options #run { float:right; width: 5em; }
1 change: 0 additions & 1 deletion docs/css/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@

#content #settings { padding: .5em 0; }
#content #settings label { padding-right: 1em; }
#content #settings label[for=option-optimize] { padding-left: 2em; }
#content #parser-var { width: 15em; }
#content #options { padding-top: 1em; }
#content #parser-download {
Expand Down
5 changes: 0 additions & 5 deletions docs/development/benchmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ <h2>Parser Generator for JavaScript</h2>
<input type="text" id="run-count" value="10"> times
<input type="checkbox" id="cache">
<label for="cache">Use results cache</label>
<label for="optimize">Optimize:</label>
<select id="optimize">
<option value="speed">Speed</option>
<option value="size">Size</option>
</select>
<input type="button" id="run" value="Run">
</div>

Expand Down
10 changes: 0 additions & 10 deletions docs/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ <h3 id="generating-a-parser-command-line">Command Line</h3>
<dd>Format of the generated parser: <code>amd</code>, <code>commonjs</code>,
<code>globals</code>, <code>umd</code>, <code>es</code> (default: <code>commonjs</code>).</dd>

<dt><code>--optimize</code></dt>
<dd>Selects between optimizing the generated parser for parsing speed
(<code>speed</code>) or code size (<code>size</code>) (default:
<code>speed</code>)</dd>

<dt><code>--plugin</code></dt>
<dd>Makes Peggy use a specified plugin (can be specified multiple
times).</dd>
Expand Down Expand Up @@ -238,11 +233,6 @@ <h3 id="generating-a-parser-javascript-api">JavaScript API</h3>
<code>source</code> in the location objects, that returned by the
<code>location()</code> API function (default: <code>undefined</code>).</dd>

<dt><code>optimize</code></dt>
<dd>Selects between optimizing the generated parser for parsing speed
(<code>"speed"</code>) or code size (<code>"size"</code>) (default:
<code>"speed"</code>).</dd>

<dt><code>output</code></dt>
<dd>If set to <code>"parser"</code>, the method will return generated parser
object; if set to <opde>"source"</code>, it will return parser source code as
Expand Down
14 changes: 4 additions & 10 deletions docs/js/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ $(document).ready(function() {
var oldGrammar = null;
var oldParserVar = null;
var oldOptionCache = null;
var oldOptionOptimize = null;
var oldInput = null;

var editor = CodeMirror.fromTextArea($("#grammar").get(0), {
Expand Down Expand Up @@ -39,22 +38,19 @@ $(document).ready(function() {
oldGrammar = getGrammar();
oldParserVar = $("#parser-var").val();
oldOptionCache = $("#option-cache").is(":checked");
oldOptionOptimize = $("#option-optimize").val();

$('#build-message').attr("class", "message progress").text("Building the parser...");
$("#input").attr("disabled", "disabled");
$("#parse-message").attr("class", "message disabled").text("Parser not available.");
$("#output").addClass("disabled").text("Output not available.");
$("#parser-var").attr("disabled", "disabled");
$("#option-cache").attr("disabled", "disabled");
$("#option-optimize").attr("disabled", "disabled");
$("#parser-download").attr("disabled", "disabled");

try {
var timeBefore = (new Date).getTime();
parserSource = peggy.generate(getGrammar(), {
cache: $("#option-cache").is(":checked"),
optimize: $("#option-optimize").val(),
output: "source"
});
var timeAfter = (new Date).getTime();
Expand All @@ -72,7 +68,6 @@ $(document).ready(function() {
$("#input").removeAttr("disabled");
$("#parser-var").removeAttr("disabled");
$("#option-cache").removeAttr("disabled");
$("#option-optimize").removeAttr("disabled");
$("#parser-download").removeAttr("disabled");

var result = true;
Expand Down Expand Up @@ -126,8 +121,7 @@ $(document).ready(function() {
function scheduleBuildAndParse() {
var nothingChanged = getGrammar() === oldGrammar
&& $("#parser-var").val() === oldParserVar
&& $("#option-cache").is(":checked") === oldOptionCache
&& $("#option-optimize").val() === oldOptionOptimize;
&& $("#option-cache").is(":checked") === oldOptionCache;
if (nothingChanged) { return; }

if (buildAndParseTimer !== null) {
Expand Down Expand Up @@ -182,7 +176,7 @@ $(document).ready(function() {

editor.on("change", scheduleBuildAndParse);

$("#parser-var, #option-cache, #option-optimize")
$("#parser-var, #option-cache")
.change(scheduleBuildAndParse)
.mousedown(scheduleBuildAndParse)
.mouseup(scheduleBuildAndParse)
Expand Down Expand Up @@ -214,8 +208,8 @@ $(document).ready(function() {
$("#loader").hide();
$("#content").show();

$("#grammar, #parser-var, #option-cache, #option-optimize").removeAttr("disabled");
$("#grammar, #parser-var, #option-cache").removeAttr("disabled");

buildAndParse();

editor.refresh();
Expand Down
5 changes: 0 additions & 5 deletions docs/online.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ <h2 class="suggestion">
<div id="options">
<input type="checkbox" id="option-cache" disabled>
<label for="option-cache">Use results cache</label>
<label for="option-optimize">Optimize:</label>
<select id="option-optimize" disabled>
<option value="speed">Parsing speed</option>
<option value="size">Code size</option>
</select>
</div>
</div>
</td>
Expand Down
1 change: 0 additions & 1 deletion lib/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const compiler = {
dependencies: {},
exportVar: null,
format: "bare",
optimize: "speed",
output: "parser",
trace: false
});
Expand Down
Loading

0 comments on commit 0427028

Please sign in to comment.