documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Document the language grammar in full

Open paf31 opened this issue 8 years ago • 11 comments

Copied from https://github.com/purescript/roadmap/issues/50

paf31 avatar Jan 17 '17 17:01 paf31

In what form do we want this documentation? BNF grammar, like this SQL BNF grammar description?

chexxor avatar Jan 28 '17 22:01 chexxor

I would like to build a plugin for Intellij - but I really need a BNF grammar. Is there any place I can find this information? Even a partial grammar documented would be helpful.

kingsleyh avatar May 20 '17 20:05 kingsleyh

Hi @kingsleyh! The closest thing we have to that is still just the compiler source code for now. It's actually not that dissimilar to a BNF grammar once you learn how to read it, though.

hdgarrood avatar May 20 '17 20:05 hdgarrood

Thanks - I will have a look and see what I can figure out and then try to build a BNF grammar

kingsleyh avatar May 20 '17 20:05 kingsleyh

I'm interested in this issue because I would like to do a direct PureScript to TypeScript transpiler that works in the browser without going to a server. I've had success doing this with Python to TypeScript and used a parser-generator called SPARK. SPARK takes a textual grammar and generates the parser. You are left to build the AST from the concrete syntax tree. A nice thing about this approach is that the grammar becomes a working software artifact with a dependent reference implementation. Here's the example parser for Python: https://github.com/geometryzen/typhon-lang. Anyone interested in taking this route to a PureScript grammar?

geometryzen avatar Jun 10 '17 14:06 geometryzen

@chexxor: Not sure it's the best fit for PureScript, but Gabriel Gonzalez used ABNF for Dhall and he seems to know what he's doing=)

seagreen avatar Oct 12 '17 05:10 seagreen

I believe the PS compiler itself doesn't use a BNF notation to generate its parser, so any BNF we maintain here could bit-rot. There was some interest in moving PS's parser to be generated from a BNF notation, so perhaps this issue should wait until that happens?

Or is there some value in having PS's current parser be approximated by a PS compiler-external BNF spec? If so, it's probably best to have someone actually write one and verify its correctness, then we copy it into here.

Regarding flavor of syntax notation, some notations support more complicated grammars than others. So, I think we just use whichever one works. :)

chexxor avatar Oct 13 '17 00:10 chexxor

I find myself wanting to refer to such a thing to look at syntax highlighting details. @kingsleyh did you ever start building such a grammar?

nwolverson avatar Jan 04 '18 20:01 nwolverson

@nwolverson He did release the IntelliJ plugin it seems: https://github.com/intellij-purescript/intellij-purescript/

sriharshachilakapati avatar Jun 07 '18 13:06 sriharshachilakapati

I'm interested in writing a PureScript interpreter in Rust (and then compiler from PS to Rust). Where can I find the most complete PS grammar description? In that intellij plugin repo I only see a Purescript.flex file used for generating the lexer..

Boscop avatar Jun 07 '18 13:06 Boscop

Hey - I tried to write a bnf for IntelliJ - however IntelliJ uses a specialised ebnf format which doesn’t support some forms of recursion - I could not get it working with good performance - so switched to using a hand rolled parser written in code. But I’ve not had any more time recently so I’ve stopped work on it for now

kingsleyh avatar Jun 07 '18 20:06 kingsleyh