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.

Postprocessor function fires for every matched character

See original GitHub issue

One of the things that’s unexpected for me as I’m testing is that, if the post processor is matching a sequence, it fires for every matched identifier, including partial matches. Is that expected? For example, if I’m matching the :extend, and I do {% d => console.log(d) %}, I get logs like (see the second item in the nested array): screen shot 2018-06-25 at 6 36 12 pm

It’s not an ambiguous grammar problem (I presume), because it produces one “parsing”. I was naively creating objects on each post-processor call, but is this behavior expected? Should I be looking for a “Ok are you really done?” flag? Is this for error handling? The brief documentation doesn’t give any indication whatsoever that partial matches of a Nearley rule will fire the post-processor, and I don’t want to create objects that are never used. Can you explain?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kachcommented, Jun 26, 2018

Yeah, a lexer would prevent this because :extend would be read by nearley in one chunk.

Tim wrote very good docs for moo — I don’t think you’ll have much trouble if you choose to go that route. On the other hand, I’d caution you to not spend too much time optimizing something if it’s not actually too slow. 😃

2reactions
tjvrcommented, Jun 27, 2018

I was trying to build a parser that had side-effects and was curious to venture down this road. Specifically, it was for AST node caching

I think “no side effects” is a bit strong, actually; what we really mean is that your AST nodes—aka what’s returned by your postprocessors—should be immutable.

Nearley may “reuse” an AST node in another parse, so if you mutate your AST nodes in-place you’re going to have a bad time.

This doesn’t necessarily stop you from writing some sort of caching system that “shares” child nodes between parent nodes; indeed if Nearley returns multiple parses, it’s likely that they will share children.

However, if what you’re really trying to do is something like common subexpression elimination, I’d probably do that as a separate step after parsing.

Sorry if the above doesn’t make sense; this stuff is hard to explain!

Sent with GitHawk

Read more comments on GitHub >

github_iconTop Results From Across the Web

Order of execution for event functions
Running a Unity script executes a number of event functions in a predetermined order. This page describes those event functions and explains how...
Read more >
Character Movement Component
Calculates movement from animation root motion and root motion sources. Calls StartNewPhysics , which selects a Phys* function based on what movement mode...
Read more >
How to Set up Your Machine in SOLIDWORKS CAM
But every time you fire it up, you always repeat the same steps, Machine, ... Download a free post processor for SOLIDWORKS CAM...
Read more >
Component Reference - Apache JMeter - User's Manual
Each sampler (except Flow Control Action) generates one or more sample results. ... When these characters are not used in their special role...
Read more >
Humanoid
The Humanoid is a special object that gives models the functionality of a character. It grants the model with the ability to physically...
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