Skip to content

peek multiple characters? #55

@cloewen8

Description

@cloewen8

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions