Skip to content

More unicode support for character parsing: anyUniCharOf and uniCharCodeWhere #98

@Pamplemousse

Description

@Pamplemousse

anyCharOf and charCodeWhere aren't adequate when parsing strings containing unicode characters:

import { anyCharOf, charCodeWhere, string } from "parjs";
import { qthen } from "parjs/combinators";

const s = "🥔";

const p1 = anyCharOf(s);
const p2 = charCodeWhere((x) => x === s.codePointAt(0) || { reason: "Bar" });

console.log([
  p1.parse(s),
  p2.parse(s),
]);

give the following result

[
  ParjsFailure {
    trace: {
      userState: ParserUserState {},
      position: 1,
      reason: 'parsers did not consume all input',
      input: '🥔',
      location: [Getter],
      stackTrace: [],
      kind: 'Soft'
    }
  },
  ParjsFailure {
    trace: {
      userState: ParserUserState {},
      position: 0,
      reason: 'Bar',
      input: '🥔',
      location: [Getter],
      stackTrace: [Array],
      kind: 'Soft'
    }
  }
]

Not unexpected, but I would like to be able to do something like this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions