Code Monkey home page Code Monkey logo

relude-parse's People

Contributors

andywhite37 avatar dependabot[bot] avatar jihchi avatar mlms13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

relude-parse's Issues

Add notChar

Add a function notChar(string) that is a shortcut for anyCharNotIn([str])

Make list-producing parsers tail recursive

I know there's a comment in the code, but I figured I'd open a more official ticket since this will probably become an issue in Relude CSV (since parsing an 8000 line CSV file doesn't seem completely out of the question).

I was looking at the MonadRec stuff in PureScript, and I think it's very similar to the trampoline technique that I was porting from Scala to Reason. I may try to do something in Relude proper, which hopefully relude-parse will be able to benefit from.

Add EOL parsers

  • carriage return
  • line feed
  • crlf
  • combination eol parser that handles the common occurrences of these
  • orEOL function?

CSV parsing challenge

For relude-csv, @mlms13 ran into an interesting scenario when trying to parse csv fields, which are delimited by ,, \r\n or \n.

You'd normally use sepBy for parsing the csv fields out, but for parsing the actual fields, you need a parser that will consume all the input up to ,, \r\n, or \n.

Using manyUntil doesn't quite work b/c manyUntil consumes the delimiter, so it messes up the sepBy.

Maybe we need something like manyUntilBacktrack which consumes all the input and the terminator, but then backtracks to the start of the terminator?

Or another idea is a not function that lets you negate a parse, so you could so many(not(anyOfStr([",", "\r\n", "\n"]))). I'll have to see how negation could work like this.

Add DateTime parsing utilities (here for now)

We plan to have a relude-datetime library eventually, but until then, we can add some basic date-time parsing utilities here. We can move them to a new lib later.

ReludeParse.DateTime.ISO8601.parse(...)

For date times, @mlms13 and I had an idea for type-safe format specs, which could be used for parsing and formatting datetimes:

module Format = {
  type t = | Lit(string) | Year4Digit | Year2Digit | etc.
};

let parse: (list(Format.t), string) => Belt.Result.t(DateTime.t, string) = List.foldLeft(...)
let format: (list(Format.t), DateTime.t) => string = ...

E.g.
parse([Year4Digit, Lit("-"), Month2Digit, Lit("-"), Day2Digit], "1999-02-03")

We'll have to make some decisions on how best to setup the format data constructors - whether they should be very specific and unambiguous vs. parameterized with ints.

e.g.

Month2DigitZeroPad
vs.
Month(int, string) // Month(2, "0")
vs.
Month2DigitWithPad(string)
etc.

The problem with int and string parameters is that they make the whole thing very open-ended and prone to error.

Add URI parsing utility (here for now)

We might eventually have a relude-uri library, but for now, we can put a basic parser for URI/URL here.

I wrote a URI paser in scala using atto, which looked something like this - I can probably port this code to relude-parse:

def uri: Parser[URI] = {
    for {
      _             <- opt(horizontalWhitespace) // strip off leading whitespace
      schemeOpt     <- opt(uriScheme)
      authorityOpt  <- opt(uriAuthority)
      path          <- uriPath
      queryOpt      <- opt(uriQuery)
      fragmentOpt   <- opt(uriFragment)
      _             <- opt(horizontalWhitespace) // strip off trailing whitespace
      _             <- endOfInput
    } yield {
      URI(schemeOpt, authorityOpt, path, queryOpt, fragmentOpt)
    }
  }

Add `show` function (or functions) for NanpPhone

It would be nice to have some show functions for NanpPhone - I'm not sure if there are different output formats, or if there is a single canonical format, but we can support whatever makes sense.

Decimal/BigDecimal parser

Once relude has more complete Decimal and/or BigDecimal types, we it would be nice to have some parsers for these data types. Since they are fairly primitive, I think those parsers can live in this repo as extras.

Like `manyUntil`, but gracefully accepts EOF

In relude-csv, I've found myself wanting to parse either until a terminator is found, or until all input is consumed. With manyUntil's current behavior, the terminator is required or parsing will fail. I don't think this is wrong, but it's a little verbose to work around:

manyUntil(str(";") |> map(ignore) <|> eof);

Maybe something like manyUntilOpt since the terminator isn't required to be present for the parser to succeed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.