What does {% id %} do?
See original GitHub issueI have read the README.md
here, and the Nearley web page. Then I was reading how-to-grammar-good.md
and I’ve read the page about Earley. I understand what regular expression, Backus Naur Form, context free grammar, terminal, nonterminal, and ambiguous grammar mean, but when it said
You should know nearley syntax well enough to understand what something like
int -> [0-9] {% id %} | int [0-9] {% function(d) {return d[0] + d[1]} %}
means
I thought: no, not fully. Where can I learn more?
I understand the declaration syntax, and I know that JavaScript snippets can be included between {%
and %}
, but what does the {% id %}
do? (I’m guessing the first argument of the function is the array of elements of the word, so the first 2 elements are returned.)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Freud's Theory of the Id in Psychology - Verywell Mind
The id acts as the driving force of personality. It not only strives to fulfill the most basic urges that people have, many...
Read more >HTML id Attribute - W3Schools
The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to...
Read more >id - HTML: HyperText Markup Language - MDN Web Docs
The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element...
Read more >ID | What Does ID Mean? - Cyber Definitions
ID means Identity. This page explains how ID is used on messaging apps such as Snapchat, Instagram, Whatsapp, Facebook, Twitter, TikTok, and Teams...
Read more >Meaning of id in English - Cambridge Dictionary
abbreviation for identification: any official card or document with your name and photograph or other information on it that you use to prove...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also, @pepa65, we do mention it in the README! https://github.com/Hardmath123/nearley#postprocessors
I guess the problem is that it’s hidden away and hard to find — and I guess the solution is to restructure the documentation to be easier to skim. Currently, we have some sort of hybrid between an in-depth tutorial and legit documentation; maybe that needs to change…
Yep, you got it right! See, it is pretty straight-forward. 😄
In the generated JS you can find this:
function id(x) {return x[0]; }
- this operation is so often-used that they include a helper for it. Since{% ... %}
can contain any JS,{% id %}
simply refers to thisid
function defined in the same file.I agree, docs are lacking sometimes. At least the syntax is intuitive.