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.

Prepare Emitter API to go public

See original GitHub issue

In preparation for #3619 and #3620 I’d live to review out Emitter API and rename some things to better match our own internal naming. I think the original was a bit too specific with regards to internal implementations and the new version should be a little more abstract:

Old:

  • addKeyword(text, scope)
  • addText(text)
  • addSublanguage(emitter, subLanguageName)
  • finalize()
  • openNode(scope)
  • closeNode()
  • closeAllNodes()
  • toHTML()

New:

  • addText(text)
  • startScope(scope) (or pushScope?)
  • endScope() (or popScope? or finishScope?)
  • __addSublanguage(emitter, subLanguageName) - (may stay private)
  • finalize() - thoughts on naming?
  • toHTML()

Removed:

  • <del>addKeyword(text, scope) </del> - pull back into an internal helper
  • <del>closeAllNodes()</del> - Lets just let finalize be responsible for all cleanup.

For writing custom grammar parsers one would really only need to concern themselves with 3 API calls I think:

  • addText
  • startScope
  • endScope

@wooorm I know you had plenty of thoughts on this before… it’s possible I’m a little more receptive now… I do plan on reducing a API a bit if we’re going public (which I recall you pushed for previously).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Sep 17, 2022

as long as there are ways to bypass the default tokenizer and there is a way to provide the actual token

That’s what #3620 allows. It should land in 11.7 (as a beta feature) with a full release with v12.

0reactions
foo123commented, Sep 17, 2022

@joshgoebel as long as there are ways to bypass the default tokenizer and there is a way to provide the actual token (parsed with an external parser), my addon is fine. I don’t have the time at this point to test it, but I will do it once it is live.

I wonder how BNF parsers tend to do with ‘getting back on track’ when presented with wholly invalid data? That’s often a thing with code snippets - incomplete context, typos, etc…

This is part of error recovery. The approach can be simple or complex. A simple approach is discard everything (eg highlight as default text) until a valid sequence is found, then start again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to code your own event emitter in Node.js: a step-by-step ...
Grab the array of listeners by 'event'; If none found return 'this' for chaining. · Return 'this' to continue chaining. ; Get the...
Read more >
EventEmitter - Angular
Creates an instance of this class that can deliver events synchronously or asynchronously. This class is "final" and should not be extended. See...
Read more >
What is the proper use of an EventEmitter? - Stack Overflow
Yes, go ahead and use it. EventEmitter is a public, documented type in the final Angular Core API. Whether or not it is...
Read more >
Understanding Event Emitters | CSS-Tricks
An event emitter is a pattern that listens to a named event, fires a callback, then emits that event with a value. Sometimes...
Read more >
React Native Event Emitter with Swift - gists · GitHub
I had to do the following to get this to work out-of-the-box: In EventEmitter.swift, make eventEmitter non-static by changing: private static var eventEmitter: ......
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