8000 Updating grammarSource documentation by AndrewRayCode · Pull Request #382 · peggyjs/peggy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Updating grammarSource documentation #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ chunpu <fengtong@mail.ustc.edu.cn> (https://github.com/chunpu/)
fatfisz <fatfisz@gmail.com> (https://github.com/fatfisz/)
fpirsch <fpirsch@free.fr> (https://github.com/fpirsch/)
markw65 <mark@replayroutes.com> (https://github.com/markw65/)
Andy (https://github.com/AndrewRayCode)
31 changes: 16 additions & 15 deletions docs/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,19 @@ <h3 id="generating-a-parser-javascript-api">JavaScript API</h3>
<code>"source-with-inline-map"</code>. (default: <code>"bare"</code>).
</dd>

<dt><code>grammarSource</code></dt>
<dd>Any object that represent origin of the input grammar. The CLI will convert
it to a string with the path to the file; parsers in network applications
might use the socket and so on. The supplied object will be available at key
<code>source</code> in the location objects, that returned by the
<code>location()</code> API function (default: <code>undefined</code>). It
is recommended that if you do not use a string, the object you supply has
a useful <code>toString()</code> implementation.
<dt id="grammar-source"><code>grammarSource</code></dt>
<dd>
A string or object representing the "origin" of the input string being
parsed. The <code>location()</code> API returns the supplied
<code>grammarSource</code> in the <code>source</code> key. As an example, if
you pass in <code>grammarSource</code> as "main.js", then errors with
locations include <code>{ source: 'main.js', ... }</code>.
<br><br>
If you pass an object, the location API returns the entire object in the
<code>source</code> key. If you format an error containing a location with
<a href="#error-messages"><code>format()</code></a>, the formatter
stringifies the object. If you pass an object, we recommend you add
a <code>toString()</code> method to the object to improve error messages.
</dd>

<dt><code>info</code></dt>
Expand Down Expand Up @@ -1409,13 +1414,9 @@ <h2 id="locations">Locations</h2>
}
</code></pre>

<p><code>source</code> is an any object that was supplied in the <code>grammarSource</code> option in
the <code>parse()</code> call. That object can be used to hold reference to the origin of
the grammar, for example, it can be a filename. It is recommended that this
object have a <code>toString()</code> implementation that returns meaningful string,
because that string will be used when getting formatted error representation
with <a href="#error-messages"><code>e.format()</code></a>.</p>

<p><code>source</code> is the a string or object that was supplied in the
<a href="#grammar-source"><code>grammarSource</code></a> parser option.</p>

<p>For certain special cases, you can use an instance of the
<code>GrammarLocation</code> class as the <code>grammarSource</code>.
<code>GrammarLocation</code> allows you to specify the offset of the grammar
Expand Down
0