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.

Multiple Lexers from the same factory can't be interleaved

See original GitHub issue

e.g.:

const factory = moo([['a', 'a'], ['b', 'b']])

const l1 = factory('ab')
const l2 = factory('ab')

l1.lex() // a
l2.lex() // b, should be a

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
tjvrcommented, Mar 12, 2017

Perhaps add reset(input)

My thoughts exactly! 😃

I think I’m gonna rename it moo.compile, to make clear that building a lexer this way is expensive (I don’t want users to be calling moo() every time they want to parse something).

0reactions
nathancommented, Mar 12, 2017

I think I measured it to have a slight cost?

I said “cheap”, not “free” 😃

Regardless, I’m still not sure what the motivation for factory() is.

Agreed. It seems like since the fastest thing to do is use a single Lexer and keep resetting it, the API should probably reflect that. Perhaps add reset(input) (or init, I’m not sure what to call it), which would do essentially the same thing as rewind(0); feed(input) but without the slicing/concatenation.

const lexer = moo({
  ws:      /[ \t]+/,
  rparen:  ')',
  keyword: ['while', 'if', 'else', 'moo', 'cows'],
  NL:      /\n/,
])

lexer.reset('while (10) cows\nmoo')
lexer.lex() // -> { name: 'keyword', value: 'while' }

lexer.reset('if (0) cats\ncattle')
lexer.lex() // -> { name: 'keyword', value: 'if'}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dr. J's Compiler and Translator Design Lecture Notes
It must know whether every two adjacent characters in the file belong together in the same token, or whether the second character must...
Read more >
flex / bison : how can I switch two lexers on same input file
Flex buffers cannot easily be transferred from one scanner to another. Many details are private to the scanner and would need to be ......
Read more >
Write your own lexer - Pygments
Using multiple lexers for the same input can be tricky. One of the easiest combination techniques is shown here: You can replace the...
Read more >
An efficient postprocessor architecture for channel mismatch ...
A pipelined post-processor architecture is proposed in this paper for digital background calibration of time interleaved ADCs.
Read more >
Code Composer Studio Development Tools v3.3
7.1.2 Multiple Versions of Code Composer Studio. ... In the Available Factory Boards pane, select a target board or simulator that represents your...
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