Debian Codegraph @

docs/index.html

raw
1 <!DOCTYPE html>
2 <title>Home - nearley.js - JS Parsing Toolkit</title>
3 <meta charset="utf-8"/>
4 <meta name="viewport" content="width=device-width, initial-scale=1">
5 <meta name="description" content="nearley.js is a simple, fast, and powerful parser toolkit for JavaScript." />
6 <style>
7 body {
8 font-family: BlinkMacSystemFont, -apple-system, Helvetica Neue, Open Sans, Ubuntu, Arial, Helvetica, sans-serif;
9 font-weight: 300;
10 font-size: 15pt;
11 margin: 0px;
12 padding: 0px;
13 }
14
15 #main a {
16 color: #55a;
17 }
18 #main a:visited {
19 color: #55a;
20 }
21 #main a:hover {
22 color: #259;
23 }
24
25 h1 {
26 font-size: 1.2em;
27 font-weight: normal;
28 letter-spacing: 0.2em;
29 text-align: center;
30 margin: 0em;
31 padding: 1em;
32 }
33
34 h1 a {
35 color: #559;
36 text-decoration: none;
37 }
38
39 h1 a:hover {
40 color: orange;
41 cursor: pointer;
42 }
43
44 #version {
45 background: orange;
46 border-radius: 50%;
47 font-weight: bold;
48 color: white;
49 width: 3em;
50 height: 3em;
51 display: inline-block;
52 text-align: center;
53 line-height: 3em;
54 letter-spacing: 0em;
55 }
56
57 h2 {
58 font-size: 1.5em;
59 margin-top: 2em;
60 }
61 h3 {
62 margin-top: 3em;
63 }
64 h4 {
65 margin-top: 3em;
66 }
67
68 .center {
69 padding-left: 2em;
70 padding-right: 2em;
71 margin-left: auto;
72 margin-right: auto;
73 }
74 #main {
75 max-width: 35em;
76 }
77
78 #main p, ul, ol {
79 line-height: 1.5em;
80 margin-bottom: 1em;
81 }
82
83 #main li {
84 margin-top: 1em;
85 margin-bottom: 1em;
86 }
87
88 #main ul li {
89 list-style: none;
90 min-width: 10em;
91 }
92 #main ul li:before {
93 display: inline-block;
94 content: "\2014";
95 margin-left: -1.5em;
96 width: 1.5em;
97 position: absolute;
98 }
99
100 #main textarea {
101 width: 100%;
102 height: 20em;
103 resize: none;
104 margin-top: 5px;
105 margin-bottom: 5px;
106
107 font-family: menlo, monaco, monospace;
108 font-size: 10pt;
109 padding: 5px;
110
111 border: none;
112 border-left: solid 1px #aaa;
113 }
114 #main textarea:focus {
115 outline: none;
116 }
117
118 #main img {
119 display: block;
120 margin-left: auto;
121 margin-right: auto;
122 max-width: 100%;
123 }
124 img + .caption {
125 text-align: center;
126 font-size: 0.7em;
127 color: #aaa;
128 }
129
130 #footer {
131 margin-top: 10em;
132 color: #aaa;
133 font-size: 0.7em;
134 padding: 5em;
135 }
136
137 code {
138 margin-left: 0.2em;
139 margin-right: 0.2em;
140 padding: 0.2em;
141 border-radius: 0.2em;
142 background-color: #eee;
143 }
144
145 pre code {
146 border-radius: 0.5em;
147 padding: 0.5em;
148 display: block;
149 overflow: auto;
150 }
151
152
153 ol {
154 counter-reset: tutorial-counter;
155 position: relative;
156 }
157
158 ol li {
159 list-style: none;
160 }
161
162 ol li:before {
163 content: counter(tutorial-counter);
164 counter-increment: tutorial-counter;
165
166 font-weight: bold;
167 border-radius: 50%;
168 background-color: #559;
169 width: 2em;
170 height: 2em;
171 display: inline-block;
172 text-align: center;
173 line-height: 2em;
174 color: white;
175
176 margin-left: -2em;
177
178 position: absolute;
179 left: 1em;
180 }
181
182 input[type="text"] {
183 border: none;
184 font-family: monospace;
185 font-size: 1em;
186 color: #559;
187 }
188
189 input[type="text"]:focus {
190 outline: none;
191 }
192
193
194 nav {
195 border-bottom: 2px solid #559;
196 background: #fafafa;
197 }
198 nav ul {
199 padding: 0;
200 margin: 0;
201 }
202 nav ul a {
203 text-decoration: none;
204 color: #334;
205 display: block;
206 overflow: hidden;
207 text-overflow: ellipsis;
208 padding: 0.25em 0.5em; */
209 }
210 .page {
211 display: block;
212 }
213
214 .page-title-active,
215 .page-heading-active a {
216 color: #66f;
217 }
218
219 .page-heading {
220 display: block;
221 padding-left: 1.5em;
222 }
223
224
225 @media screen and (min-width: 36rem) {
226 nav {
227 position: fixed;
228 width: 16rem;
229 left: 0;
230 top: 0;
231 bottom: 0;
232 white-space: nowrap;
233 overflow-y: auto;
234 font-size: 1rem;
235 border-bottom: none;
236 border-right: 2px solid #559;
237 }
238 body.docs-page {
239 margin-left: 16rem;
240 }
241 }
242
243 /* highlight.js */
244
245 .hljs{display:block;overflow-x:auto;padding:0.5em;background:#F0F0F0}.hljs,.hljs-subst{color:#444}.hljs-comment{color:#888888}.hljs-keyword,.hljs-attribute,.hljs-selector-tag,.hljs-meta-keyword,.hljs-doctag,.hljs-name{font-weight:bold}.hljs-type,.hljs-string,.hljs-number,.hljs-selector-id,.hljs-selector-class,.hljs-quote,.hljs-template-tag,.hljs-deletion{color:#880000}.hljs-title,.hljs-section{color:#880000;font-weight:bold}.hljs-regexp,.hljs-symbol,.hljs-variable,.hljs-template-variable,.hljs-link,.hljs-selector-attr,.hljs-selector-pseudo{color:#BC6060}.hljs-literal{color:#78A960}.hljs-built_in,.hljs-bullet,.hljs-code,.hljs-addition{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta-string{color:#4d99bf}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:bold}
246
247
248 </style>
249
250 <body class="docs-page">
251
252 <a href="https://github.com/kach/nearley" class="github-corner"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
253 <nav id="nav">
254 <h1><a href="/">nearley<span style="color: #559;">.js</span><span id="version">2.20.0</span></a></h1>
255 <ul>
256 <li class="page">
257 <a href="#" class="page-title-active">Home</a>
258 <ul>
259 <li class="page-heading"><a href="#nearley-101">nearley 101</a>
260 <li class="page-heading"><a href="#features">Features</a>
261 <li class="page-heading"><a href="#projects-using-nearley">Projects using nearley</a>
262 <li class="page-heading"><a href="#give-to-nearley">Give to nearley</a>
263 </ul>
264 </li>
265 <li class="page"><a href="/docs/getting-started">Getting started</a>
266 <li class="page"><a href="/docs/grammar">Writing a parser</a>
267 <li class="page"><a href="/docs/parser">Using a parser</a>
268 <li class="page"><a href="/docs/tokenizers">Tokenizers</a>
269 <li class="page"><a href="/docs/tooling">Tooling</a>
270 <li class="page"><a href="/docs/how-to-grammar-good">How to grammar good</a>
271 <li class="page"><a href="/docs/using-in-frontend">Compiling in browsers</a>
272 <li class="page"><a href="/docs/glossary">Glossary</a>
273 </ul>
274 </nav>
275
276 <div id="main" class="center">
277
278 <h2>Home</h2>
279 <p><strong>Parsers</strong> turn strings of characters into meaningful data structures (like a
280 JSON object!). <strong>nearley</strong> is a <strong>fast</strong>, <strong>feature-rich</strong>, and <strong>modern</strong>
281 parser toolkit for JavaScript. nearley is an <a href="https://github.com/npm/npm-collection-staff-picks">npm Staff
282 Pick</a>.</p>
283 <h3 id="nearley-101">nearley 101</h3>
284 <ol>
285 <li>Install: <code>$ npm install -g nearley</code> (or try nearley live in your browser
286 <a href="https://omrelli.ug/nearley-playground/">here</a>!)</li>
287 <li>Write your grammar:<pre><code class="language-ne"># Match a CSS color
288 # http://www.w3.org/TR/css3-color/#colorunits
289 @builtin &quot;whitespace.ne&quot; # `_` means arbitrary amount of whitespace
290 @builtin &quot;number.ne&quot; # `int`, `decimal`, and `percentage` number primitives
291 csscolor -&gt; &quot;#&quot; hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit
292 | &quot;#&quot; hexdigit hexdigit hexdigit
293 | &quot;rgb&quot; _ &quot;(&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;)&quot;
294 | &quot;hsl&quot; _ &quot;(&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;)&quot;
295 | &quot;rgba&quot; _ &quot;(&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ decimal _ &quot;)&quot;
296 | &quot;hsla&quot; _ &quot;(&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ colnum _ &quot;,&quot; _ decimal _ &quot;)&quot;
297 hexdigit -&gt; [a-fA-F0-9]
298 colnum -&gt; int | percentage</code></pre>
299 </li>
300 <li>Compile your grammar:<pre><code class="language-bash">$ nearleyc csscolor.ne -o csscolor.js</code></pre>
301 </li>
302 <li>Test your grammar:<pre><code class="language-bash">$ nearley-test -i &quot;#00ff00&quot; csscolor.js
303 Parse results:
304 [ [ &#39;#&#39;, [ &#39;0&#39; ], [ &#39;0&#39; ], [ &#39;f&#39; ], [ &#39;f&#39; ], [ &#39;0&#39; ], [ &#39;0&#39; ] ] ]</code></pre>
305 </li>
306 <li>Turn your grammar into a generator:<pre><code class="language-bash">$ nearley-unparse -n 3 csscolor.js</code></pre>
307 <pre><code>#Ab21F2
308 rgb ( -29.889%,7,8172)
309 #a40</code></pre></li>
310 <li>You try it! Type a CSS color here:<input type="text" id="parse-input" placeholder="rgba(0, 255, 0, 0.5)" />
311 <pre><code id="parse-output">…and the parsed output will appear here!</code></pre></li>
312 <li>Create beautiful railroad diagrams to document your grammar formally.<pre><code class="language-bash">$ nearley-railroad csscolor.ne -o csscolor.html</code></pre>
313 See a demo <a href="/www/railroad-demo">here</a>.</li>
314 </ol>
315 <h3 id="features">Features</h3>
316 <ul>
317 <li>nearley is the first JS parser to use the <strong>Earley</strong> algorithm (insert your
318 own ‘early bird’ pun here). It also implements Joop Leo’s optimizations for
319 right-recursion, making it effectively <strong>linear-time</strong> for LL(k) grammars.</li>
320 <li>nearley lives happily in <strong>node</strong>, but doesn’t mind the <strong>browser</strong>.</li>
321 <li>nearley outputs <strong>small</strong> files. And its <strong>expressive</strong> DSL comes with
322 plenty of <strong>syntactic sugar</strong> to keep your source files short. And sweet.</li>
323 <li>nearley’s grammar language is powerful and expressive: you can use
324 <strong>macros</strong>, import from a large <strong>builtin library</strong> of pre-defined
325 parser-pieces, use a <strong>tokenizer</strong> for extra performance, and more!</li>
326 <li>nearley is built on an idiomatic <strong>streaming API</strong>. You even have access to
327 partial parses to build <strong>predictive</strong> user interfaces.</li>
328 <li>nearley processes <strong>left recursion</strong> without choking. In fact, nearley will
329 parse anything you throw at it without complaining or going into a <del>sulk</del>
330 infinite loop.</li>
331 <li>nearley handles <strong>ambiguous grammars</strong> gracefully. Ambiguous grammars can
332 be parsed in multiple ways: instead of getting confused, nearley gives you
333 all the parsings (in a deterministic order!).</li>
334 <li>nearley allows for debugging with generous <strong>error detection</strong>. When it
335 catches a parse-time error, nearley tells you exactly what went wrong and
336 where.</li>
337 <li>nearley is powerful enough to be <strong>bootstrapped</strong>. That means nearley uses
338 nearley to compile parts of nearley. <em>nearleyception!</em></li>
339 <li>nearley parsers can be inverted to form <strong>generators</strong> which output random
340 strings that match a grammar. Useful for writing <strong>test cases</strong>,
341 <strong>fuzzers</strong>, and <strong>Mad-Libs</strong>.</li>
342 <li>You can export nearley parsers as <strong>railroad diagrams</strong>, which provide
343 easy-to-understand documentation of your grammar.</li>
344 <li>nearley comes with fantastic tooling. You can find editor plug-ins for
345 <strong>vim</strong>, <strong>Sublime Text</strong>, <strong>Atom</strong>, and <strong>VS Code</strong>; there are also
346 plug-ins for <strong>Webpack</strong> and <strong>gulp</strong>.</li>
347 </ul>
348 <h3 id="projects-using-nearley">Projects using nearley</h3>
349 <p><strong>Artificial Intelligence, NLP, Linguistics</strong>:
350 <a href="https://github.com/ChalmersGU-AI-course/shrdlite-course-project">Shrdlite</a> is
351 a programming project in Artificial Intelligence, a course given at the
352 University of Gothenburg and Chalmers University of Technology. It uses nearley
353 for reading instructions in natural language (i.e. English).
354 <a href="https://github.com/fauxneticien/lexicon-grammars">lexicon-grammars</a> was used
355 to parse lexicons for a project at Australian National University.</p>
356 <p><strong>Standard formats</strong>: <a href="https://github.com/raymond-h/node-dmi">node-dmi</a> is a
357 module that reads iconstate metadata from BYOND DMI files,
358 <a href="https://github.com/inukshuk/edtf.js">edtf.js</a> is a parser for Extended Date
359 Time Format, <a href="https://github.com/farskipper/node-krl-parser">node-krl-parser</a>
360 is a KRL parser for node,
361 <a href="https://github.com/digitalheir/bibliography-js">bibliography</a> is a
362 BibTeX-to-HTML converter,
363 <a href="https://github.com/fiduswriter/biblatex-csl-converter">biblatex-csl-converter</a>
364 converts between bibtex/CSL/JSON, <a href="https://github.com/gajus/scalpel">scalpel</a>
365 parses CSS selectors (powering <a href="https://github.com/airbnb/enzyme">enzyme</a>,
366 Airbnb’s React testing tool),
367 <a href="https://github.com/waratuman/rfc5545-rrule">rfc5545-rrule</a> helps parse
368 iCalendar data, <a href="https://github.com/mangudai/mangudai">mangudai</a> parses RMS
369 scripts for Age of Empires II, <a href="https://github.com/r24y/tf-hcl">tf-hcl</a> parses
370 and generates HCL config files,
371 <a href="https://github.com/balbuf/css-selector-inspector">css-selector-inspector</a>
372 parses and tokenizes CSS3 selectors,
373 <a href="https://github.com/mahirshah/css-property-parser">css-property-parser</a>
374 validates and expands CSS shorthands,
375 <a href="https://github.com/hhornbacher/node-scad-parser">node-scad-parser</a> parses
376 OpenSCAD 3D models, <a href="https://github.com/justinkenel/js-sql-parse">js-sql-parse</a>
377 parses SQL statements, <a href="https://github.com/oguimbal/pg-mem">pg-mem</a> is an in-memory Postgres database emulator, <a href="https://github.com/appology/resp-parser">resp-parser</a> is
378 a parser for the RESP protocol, <a href="https://github.com/AntonShan/Celio">celio</a>
379 parses Celestia star catalogs.</p>
380 <p><strong>Templating and files</strong>: <a href="https://github.com/bobbybee/uPresent">uPresent</a> is a
381 markdown-based presentation authoring system,
382 <a href="https://github.com/rtsao/saison">saison</a> is a minimal templating language,
383 <a href="https://github.com/imsky/packdown">Packdown</a> is a tool to generate
384 human-readable archives of multiple files.</p>
385 <p><strong>Programming languages</strong>: <a href="https://github.com/bobbybee/carbon">Carbon</a> is a C
386 subset that compiles to JavaScript, optimized for game development,
387 <a href="https://github.com/tleb/ezlang">ezlang</a> is a simple language,
388 <a href="https://github.com/liam4/tlnccuwagnf">tlnccuwagnf</a> is a fun general-purpose
389 language, <a href="https://github.com/nanalan/g">nanalang</a> is a silly esoteric
390 language, <a href="https://github.com/nanalan/english">english</a> is a less esoteric
391 programming language, <a href="https://github.com/farskipper/ecmaless">ecmaless</a> is an
392 easily-extensible language, <a href="https://github.com/xodio/hm-parser">hm-parser</a>
393 parses Haskell-like Hindley-Milner type signatures,
394 <a href="https://github.com/kozily/web">kozily</a> implements the Oz language,
395 <a href="https://stefan1niculae.github.io/abstract-machine/">abstract-machine</a> inspects
396 execution models, <a href="https://github.com/Malpaux/fbp-types">fbp-types</a> provides
397 typechecking primitives for flow-based systems,
398 <a href="https://github.com/sizigi/lp5562">lp5562</a> is an assembler for the TI LP5562
399 LED driver, <a href="https://github.com/vsl-lang/VSL">VSL</a> is a Versatile Scripting
400 Language, <a href="https://github.com/juanlaube/while-typescript">while-typescript</a> is
401 an implementation of the WHILE language,
402 <a href="https://github.com/lo-language/velo">lo</a> is a language for secure distributed
403 systems, <a href="https://github.com/calculemuscode/jaco">jaco</a> is an implementation of
404 CMU’s C0 teaching language, <a href="https://github.com/ballercat/walt">walt</a> is a
405 subset of JavaScript that targets WebAssembly.</p>
406 <p><strong>Mathematics</strong>: <a href="https://github.com/andrejewski/solvent">Solvent</a> is a
407 powerful desktop calculator,
408 <a href="https://github.com/andrejewski/truth-table">Truth-table</a> is a tool to
409 visualize propositional logic in truth tables, <a href="http://emunotes.com">Emunotes</a>
410 is a personal Wiki with inline graphing and computation,
411 <a href="https://kgram.github.io/react-equation/">react-equation</a> parses and renders
412 equations in React, <a href="https://github.com/cemulate/the-mlab">the mLab</a> generates
413 category theory papers.</p>
414 <p><strong>Domain-specific languages</strong>: <a href="https://github.com/jcorbin/hexant">Hexant</a> is a
415 cellular automata simulator with a DSL for custom automata,
416 <a href="https://github.com/justjake/dicetower">Dicetower</a> is an advanced dice plugin
417 for hubot, <a href="https://github.com/seiyria/deck.zone">deck.zone</a> is a language to
418 create board games, <a href="https://github.com/danigb/in-seconds">in-seconds</a> is a
419 time calculator for music applications,
420 <a href="https://github.com/bumbu/website-spec">website-spec</a> is a tool for functional
421 web testing, <a href="https://github.com/gajus/pianola">pianola</a> allows declarative
422 function composition, <a href="https://idyll-lang.github.io/idyll/">idyll</a> is a markup
423 language for data-driven documents,
424 <a href="https://github.com/affinipay/virtsecgroup">virtsecgroup</a> provides virtual AWS
425 security groups, <a href="https://github.com/Pwootage/deadfad">deadfad</a> is a hex editor
426 that lets you specify structs,
427 <a href="https://github.com/juliankrispel/bishbosh">bishbosh</a> helps you create
428 command-line interfaces, <a href="https://github.com/sgmap/syso">syso</a> codifies aspects
429 of French legal contracts,
430 <a href="https://github.com/independentgeorge/siteswap.js">siteswap</a> parses Siteswap
431 notation for juggling patterns, <a href="https://github.com/amireh/jsgrep">jsgrep</a>
432 provides syntactic grep for JavaScript,
433 <a href="https://github.com/monostable/electro-grammar">electro-grammar</a> parses
434 descriptions of electronic components like resistors and capacitors,
435 <a href="https://github.com/accordproject">cicero</a> helps create smart legal contracts,
436 <a href="https://geteventbot.com">Eventbot</a> is a calendar plugin for Slack used by
437 thousands of teams, <a href="https://github.com/byteball/ocore">Obyte</a> is a
438 cryptocurrency platform, <a href="https://github.com/linkedin/opticss">OptiCSS</a> is a
439 CSS optimizer built by LinkedIn,
440 <a href="https://github.com/cutelabnyc/nested-tuplets">NESTUP</a> is a language for
441 specifying nested rhythmic tuplets.</p>
442 <p><strong>Other</strong>:
443 <a href="https://github.com/PatrickMurphy/ProceduralPsychEpisode">ProceduralPsychEpisode</a>
444 generates “random episodes of the hilarious but formulaic show”</p>
445 <p><strong>Parsing libraries</strong>: <a href="http://nearley.js.org">nearley</a> is a parser toolkit for
446 JavaScript. It has a nearley-based DSL to specify parsers.</p>
447 <!--Excited? Get started on [Github](https://github.com/Hardmath123/nearley),
448 visit us on [npm](http://npmjs.org/package/nearley), explore nearley in your
449 browser on the [playground](https://omrelli.ug/nearley-playground/), or try out
450 the [calculator demo](examples/calculator/) for more action.-->
451
452 <h3 id="give-to-nearley">Give to nearley</h3>
453 <p>nearley has been maintained by volunteers since 2014. If you want to help
454 support us, contact <strong>@kach</strong> or <strong>@tjvr</strong> on GitHub. We’ll send over our
455 PayPal information – and maybe something nice. :-).</p>
456
457
458 <div id="footer"><p>nearley is MIT-licensed. It's maintained by <a
459 href="http://hardmath123.github.io">Hardmath123</a> (<a
460 href="http://github.com/Hardmath123">Github</a>). You're welcome to
461 leave questions, comments, advice, or ideas as Github issues. And
462 feel free to fork nearley with your own experiments!<br/>
463
464 <a href="https://js.org" target="_blank" title="JS.ORG | JavaScript Community">
465 <img src="https://logo.js.org/dark_horz.png" width="102" alt="JS.ORG Logo"/></a>
466 </div>
467
468 <script id="highlight-js" async src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
469 <script>
470 document.querySelector('#highlight-js').addEventListener('load', function() {
471 [].slice.apply(document.querySelectorAll('pre code')).forEach(function(b) {
472 hljs.highlightBlock(b)
473 })
474 })
475 </script>
476
477 <script charset="utf-8" src="/lib/nearley.js"></script>
478 <script charset="utf-8" src="/examples/js/csscolor.js"></script>
479 <script type="text/javascript">
480 window.addEventListener('load', function() {
481 document.getElementById('parse-input').addEventListener('keyup', function() {
482 // $ ./bin/nearleyc.js examples/csscolor.ne -o examples/js/csscolor.js
483 var str = this.value;
484 var parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart);
485 try {
486 parser.feed(str);
487 document.getElementById('parse-output').innerHTML = JSON.stringify(parser.results, null, 2);
488 this.style.color = "#559";
489 } catch(e) {
490 document.getElementById('parse-output').innerHTML = "";
491 this.style.color = "red";
492 }
493 }, false);
494 }, false);
495 </script>
496
497 <script>
498 window.addEventListener('scroll', onScroll)
499 window.addEventListener('resize', onScroll)
500
501 var timeout
502 function onScroll(e) {
503 if (timeout) clearTimeout(timeout)
504 timeout = setTimeout(scrollEnd, 50)
505 }
506
507 function scrollEnd() {
508 var headings = document.querySelectorAll('h3')
509 var offset = 60
510 for (var i=headings.length; i--; ) {
511 var h3 = headings[i]
512 if (h3.offsetTop < window.scrollY + offset) {
513 var cur = document.querySelector('.page-heading-active')
514 if (cur) cur.className = 'page-heading'
515 document.querySelector('a[href="#' + h3.id + '"]').parentNode.className = 'page-heading page-heading-active'
516 return
517 }
518 }
519 }
520 </script>
521
522 <script>
523 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
524 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
525 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
526 })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
527 ga('create', 'UA-46120535-5', 'auto');
528 ga('send', 'pageview');
529 </script>
530