Skip to content

add: CPC_CHAR parser - #21

Draft
taimoorzaeem wants to merge 1 commit into
PostgREST:masterfrom
taimoorzaeem:cpc-char
Draft

taimoorzaeem wants to merge 1 commit into
PostgREST:masterfrom
taimoorzaeem:cpc-char

Conversation

@taimoorzaeem

@taimoorzaeem taimoorzaeem commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Adds a single character parser. It also works with CPC_LABEL.

  • Implementation
  • Tests
  • Docs

Closes #15.

@taimoorzaeem
taimoorzaeem marked this pull request as draft November 16, 2026 10:32
Adds a single character parser. It also works with `CPC_LABEL`.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
@taimoorzaeem
taimoorzaeem marked this pull request as ready for review November 16, 2026 12:57
Comment thread cparsec.h
Comment on lines +262 to +267
if (input.len == 0) return cpc_res_err(input, "eof", err); \
\
if (input.ptr[0] == ch) \
return cpc_res_take(input, 1); \
else \
return cpc_res_err(input, "mismatch", err); \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I had a problem before when having two different error messages on CPC_STRING, check:

https://github.com/PostgREST/cparsec/blob/43e9a0b2518804c3544f8996ba9449cfe0f52935/cparsec.h#L245-L248

(for some reason github previews are not working here 😕 )

So before I also had two different error messages there, one for the short string and another for the mismatch.

The problem comes when overriding the error message with CPC_LABEL, what if we want to override only one? That's one of the reasons why before there was a more complex interface, a _LABEL variant for each parser. I removed those after #4.

So I'm thinking we should only have a single error message for each parser; only to not deal with a more complex interface.

WDYT? In Haskell you usually replace a single message from the original parser right? TBH I haven't researched this part very well, I just thought the current CPC_LABEL is good enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem comes when overriding the error message with CPC_LABEL, what if we want to override only one? That's one of the reasons why before there was a more complex interface, a _LABEL variant for each parser. I removed those after #4.

So I'm thinking we should only have a single error message for each parser; only to not deal with a more complex interface.

WDYT? In Haskell you usually replace a single message from the original parser right? TBH I haven't researched this part very well, I just thought the current CPC_LABEL is good enough.

The above makes sense, will try to look into it.

@taimoorzaeem
taimoorzaeem marked this pull request as draft November 16, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add CPC_CHAR combinator

2 participants