#How easy could be create a parsing system (like leex and yecc) in Gleam?

1 messages ยท Page 1 of 1 (latest)

hexed mirage
#

It's not weird think that a language could be compiled using the same language, most of the general purpose languages finally do that in some way, maybe using a small bootstrap precompiled and then recompiling everything using the compiler (that's the first thing to be created).

In Erlang there is a LALR-1 parser generator (yecc) and Robert Virding created LL(1) parser generator for Erlang and LFE (spell1) or even we have available PEGs (neotoma), but although it's the easier one to grasp maybe it's the less performant.

In addition, because I'm implementing a database system using Gleam, a tool like this could help me implementing a SQL-like language or even parsing better the commands receive through the network connection.

What do you think?

winter prawn
#

no more difficult/easy than creating those things in other functional languages ๐Ÿ™‚ outside of no being able to produce binaries (so running a program like yacc is a bit of a hassle) gleam is not really uniquely advantaged or disadvantaged in that regard.

i maintain a parser combinator package that includes a lexer api, for example. there are other parser packages out there too ๐Ÿ™‚

I don't think anyone has written a parser generator yet though

hexed mirage
#

@winter prawn you have experience, do you think it could be very difficult to do?

#

well, I wasn't expressing correctly, sorry, do you think it could be feasible to be done in a month or two months? what are the risks or unknowns you think that could be slowing down it?

winter prawn
#

how feasible woudl you find this in a language you are familiar with, and how similar is that language to gleam ยฏ_(ใƒ„)_/ยฏ

hexed mirage
#

good questions ๐Ÿ˜„

winter prawn
#

https://hexdocs.pm/nibble/1.0.0-rc.3/nibble.html here is the package i maintain, it's currently release-candidate because i haven't finished documentation but the api is basically stable, if you'd rather something off-the-shelf. it's not a parser generator library, and is almost certainly slower than a handwritten or generated parser, but for something like a sql-y language or passing commands it wouldn't really be a problem

hexed mirage
#

great! thanks!

hexed mirage
#

@winter prawn about nibble, I'm using it and for tokens is clear but the example is retrieving an integer and it's failing for me ๐Ÿ˜ฆ

#
  let parser = {
    use _ <- do(nibble.token(LParen))
    use x <- do(int_parser())
    use _ <- do(nibble.token(Comma))
    use y <- do(int_parser())
    use _ <- do(nibble.token(RParen))

    return(Point(x, y))
  }

int_parser is not defined

winter prawn
#

oh you just need to define int_parser first ๐Ÿ™‚ or pull it out and define it as a function at the top-level

hexed mirage
#

I just found the examples in the repository and I'm copying from JSON example, it's working ๐Ÿ™‚ ... sorry about trigger instead of searching first ๐Ÿ˜›

winter prawn
#

nah you're all good, very happy to be pinged for help ๐Ÿ™‚ there are no docs really, i cant expect folks to know!

hexed mirage
#

I left you an issue in the project and a suggestion for getting a case-insenstive solution for token, but only an idea, not sure if that works as is

winter prawn
#

awesome thanks!