Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peek multiple characters? #55

Open
cloewen8 opened this issue Sep 19, 2022 · 0 comments
Open

peek multiple characters? #55

cloewen8 opened this issue Sep 19, 2022 · 0 comments

Comments

@cloewen8
Copy link

My goal is to peek '\u{D3}' which is counted as 2 characters and perform a test, otherwise start a span.

I'm not very familiar with llparse and can't find any documentation on how to do this. I tried using select, but would then need to re-add the first character. How would I peek multiple characters or re-prepend the first character?

Here is what I had (based on llhttp):

n('header_field_start') // Match node
  .match('\r', n('headers_almost_done'))
  .peek('\n', n('headers_almost_done'))
  .peek(
    '\u{D3}', // 2 characters
    this.testLenientFlags(
      LENIENT_FLAGS.NTRIP, 
      {
        1: this.invokePausable('on_chunk_complete', ERROR.CB_CHUNK_COMPLETE, 'message_done') // If NTRIP is set
      },
      p.error(ERROR.INVALID_VERSION, 'Invalid major version') // Otherwise
    )
  )
  .otherwise(span.headerField.start(n('header_field')));

// Defined earlier...
private testLenientFlags(flag: LENIENT_FLAGS, map: { [key: number]: Node }, next?: string | Node): Node {
  const p = this.llparse;
  const res = p.invoke(p.code.test('lenient_flags', flag), map);
  if (next !== undefined) {
    res.otherwise(this.node(next));
  }
  return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant