PostgREST / PostgREST/CParseC

Total Parser Combinators - Agdarsec

Open
#7 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
91
Forks
3
Avg merge
13d 22h
Merged PRs (30d)
1

Description

Problem

Currently all our parsers terminate, but this is done by a check at runtime:

https://github.com/steve-chavez/CParseC/blob/2ec0da5107febbef3b1ffce02f842a24a8542a5d/cparsec.h#L164-L166

It'd be much better for this to not be possible at compile time

Research

I've found this paper on agdarsec (https://github.com/gallais/agdarsec/). A parser combinator library for Agda, which has "total parser combinators", that is parsers combinators that always terminate.

To do that it adds constraints and tradeoffs:

  • For a parser to be successful, it must consume some of its input
  • Failure is implemented by always returning the empty result list.
  • Several combinators are incompatible, like many, sepby, etc. Essentially all the ones that succeed on zero or more occurrences.
  • eof is not representable by agdarsec
  • There is no pure parser (since it succeeds but doesn't have to consume input)

Some breaking changes might be acceptable but one thing I'm not sure is it's expressive enough. I haven't found many examples.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the runtime termination check in cparsec.h at lines 164–166, then read the linked agdarsec paper and compare its constraints with the existing parser combinators. Determine whether a total design remains expressive enough, including the listed incompatible combinators and breaking changes. Done means documenting a concrete design direction and its tradeoffs.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.