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

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

Open
Pamplemousse opened this issue Jan 22, 2024 · 1 comment

Comments

@Pamplemousse
Copy link

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.

@GregRos
Copy link
Owner

GregRos commented Feb 5, 2024

This happens to run into an inherent limitation of Parjs and JavaScript's way of representing characters. But I definitely think it should be supported. It will probably wait for a major version release.

I've wrote up a proposal here: #100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants