question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What does {% id %} do?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kachcommented, Jun 6, 2017

Also, @pepa65, we do mention it in the README! https://github.com/Hardmath123/nearley#postprocessors

data is an array whose elements match the nonterminals in order. The postprocessor id returns the first token in the match (literally function(data) {return data[0];}).

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…

1reaction
deltaideacommented, Jun 6, 2017

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 this id function defined in the same file.

I agree, docs are lacking sometimes. At least the syntax is intuitive.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found