Skip to content

Commit

Permalink
deploy: cdf0caf
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Oct 3, 2024
1 parent a01bdec commit 43992ce
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 11 deletions.
1 change: 0 additions & 1 deletion css/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
#content .message.disabled { color: gray; background-color: #f0f0f0; }

#content table.online { table-layout: fixed; }
#content table#columns { table-layout: fixed; }

#content table.form { width: 100%; }
#content table.form td, table.form th { padding: .5em 1em; }
Expand Down
61 changes: 59 additions & 2 deletions documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ <h2 id="table-of-contents">Table of Contents</h2>
<li><a href="#error-reporting">Error Reporting</a></li>
</ul>
</li>
<li>
<a href="#typescript-types">Generating TypeScript Types</a>
</li>
</ul>
</li>
<li><a href="#using-the-parser">Using the Parser</a></li>
Expand Down Expand Up @@ -216,6 +219,12 @@ <h3 id="generating-a-parser-command-line">Command Line</h3>
<dd>Dependencies, in JSON object format with variable:module pairs. (Can be
specified multiple times).</dd>

<dt><code>--dts</code></dt>
<dd>Generate a .d.ts file next to the output .js file containing TypeScript
types for the generated parser. See <a href="#typescript-types">Generating
TypeScript Types</a> for more information.
</dd>

<dt><code>-e</code>, <code>--export-var &lt;variable&gt;</code></dt>
<dd>Name of a global variable into which the parser object is assigned to when
no module loader is detected.</dd>
Expand Down Expand Up @@ -255,6 +264,15 @@ <h3 id="generating-a-parser-command-line">Command Line</h3>
specified
</dd>

<dt><code>--return-types &lt;JSON object&gt;</code></dt>
<dd>If <code>--dts</code> is specified, the <code>typeInfo</code> provided
will be used to specify the return type of the given rules.
<code>typeInfo</code> should be specified as a JSON object whose keys are
rule names and whose values are strings containing the return type for that
rule. See <a href="#typescript-types">Generating TypeScript Types</a> for
more information.
</dd>

<dt><code>-S</code>, <code>--start-rule &lt;rule&gt;</code></dt>
<dd>When testing, use this rule as the start rule. Automatically added to
the allowedStartRules.</dd>
Expand Down Expand Up @@ -371,7 +389,7 @@ <h4 id="importing">Importing</h4>

<pre><code class="language-javascript">import peggy from "peggy";</code></pre>

<p>With some configurations of Typescript or other tools, you might need:</p>
<p>With some configurations of TypeScript or other tools, you might need:</p>

<pre><code class="language-javascript">import * as peggy from "peggy";</code></pre>

Expand Down Expand Up @@ -546,6 +564,27 @@ <h4 id="error-reporting">Error Reporting</h4>
<li><code>generate</code></li>
</ul>

<h3 id="typescript-types">Generating TypeScript Types</h3>
<p>If you are consuming the generated parser from TypeScript, it is useful for
there to be a .d.ts file next to the generated .js file that describes the
types used in the parser. To enable this, use a configuration file such as:</p>

<pre><code class="language-js">// MJS
export default {
input: "foo.peggy",
output: "foo.js",
dts: true,
returnTypes: {
foo: "string",
},
};</code></pre>

<p>If a rule name is in the allowedStartRules, but not in returnTypes,
<code>any</code> will be used as the return type for that rule.</p>
<p>Note that <code>--return-types &lt;JSON object&gt;</code> can be specified
on the command line; the use of a config file just makes quoting easier to get
correct.</p>

<h2 id="using-the-parser">Using the Parser</h2>

<p>To use the generated parser, import it using your selected module approach
Expand Down Expand Up @@ -1729,6 +1768,20 @@ <h2 id="plugins-api">Plugins API</h2>
That method will be called for all plugins in the <code>options.plugins</code>
array, supplied to the <code>generate()</code> method.</p>

<p>Plugins suitable for use on the command line can be written either as CJS
or MJS modules that export a "use" function. The CLI loads plugins with
<code class="language-js">await(plugin_name)</code>, which should
correctly load from node_modules, a local file starting with "/" or "./",
etc. For example:</p>

<pre><code class="language-js">// CJS
exports.use = (config, options) => {
}</code></pre>

<pre><code class="language-js">// MJS
export function use(config, options) => {
}</code></pre>

<p><code>use</code> accepts these parameters:</p>

<h3><code>config</code></h3>
Expand Down Expand Up @@ -1786,8 +1839,12 @@ <h3><code>options</code></h3>

<p>Build options passed to the <code>generate()</code> method. A best practice
for a plugin would look for its own options under a
<code>&lt;plugin_name&gt;</code> key.</p>
<code>&lt;plugin_name&gt;</code> key:</p>

<pre><code class="language-js">// File: foo.mjs
export function use(config, options) => {
const mine = options['foo_mine'] ?? 'my default';
}</code></pre>

<h3 id="session-api">Session API</h3>

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2>Parser Generator for JavaScript</h2>
<div class="label">Download browser version</div>
<span id="download">
<a title="Download a minified version of Peggy for the browser"
href="https://unpkg.com/peggy@4.0.3/browser/peggy.min.js">minified</a>
href="https://unpkg.com/peggy@4.1.1/browser/peggy.min.js">minified</a>
</span>
<iframe id="discord"
src="https://discordapp.com/widget?id=985995982909100082&theme=dark"
Expand Down
4 changes: 2 additions & 2 deletions js/benchmark-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/examples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by Peggy 4.0.3.
// @generated by Peggy 4.1.1.
//
// https://peggyjs.org/
(function(root) {
Expand Down
4 changes: 2 additions & 2 deletions js/test-bundle.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions vendor/peggy/peggy.min.js

Large diffs are not rendered by default.

0 comments on commit 43992ce

Please sign in to comment.