Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax diagram #1810

Closed
vanillajonathan opened this issue Feb 12, 2023 · 7 comments
Closed

Syntax diagram #1810

vanillajonathan opened this issue Feb 12, 2023 · 7 comments

Comments

@vanillajonathan
Copy link
Collaborator

The website and/or documentation should include a syntax diagram.

@max-sixty
Copy link
Member

I think let's merge this into #12 given how intertwined it is, let me add a comment there.

@max-sixty
Copy link
Member

Actually #12 is closed.

But this relies on defining a formal grammar which we don't have at the moment, and I probably wouldn't suggest we write yet, given we'd need to keep it up to date, and we're still making changes to the language — at least unless someone wants to write it and commit to maintain it...

We already have 4 grammar definitions (https://prql-lang.org/book/internals/syntax-highlighting.html)!

To the extent we could make something out of an existing grammar — 
https://github.com/PRQL/prql/blob/main/prql-lezer/src/prql.grammar is probably the most formal — let's reopen this. Otherwise let's wait until the language changes have mostly come to a halt.

Is that reasonable @vanillajonathan ?

@vanillajonathan
Copy link
Collaborator Author

Sure it can be postponed until later, right now might not be the best time, but you can add it on to some "to do" list using some issue tag, milestone or a project.

@max-sixty
Copy link
Member

Good idea — added a label. We can do a search of closed issues with this label in future

@vanillajonathan
Copy link
Collaborator Author

vanillajonathan commented Feb 14, 2023

I wrote some EBNF grammar for PRQL.

Statements ::= Statement Comment? | (('|' | NEWLINE) Statement)* Comment?
Statement ::= Assignment | FunctionCall
Array ::= '[' SPACE* Name? SPACE* (',' SPACE* Name SPACE* ','?)* ']'
Atom ::= 'true' | 'false' | 'null'
Comment ::= '#' '*'*
Name ::= '_'* ALPHA+ (ALPHANUM | '_')*
DateInner ::= (DIGIT+ '-' DIGIT+ '-' DIGIT+)
TimeInner ::= (DIGIT+ ':' DIGIT+ ':' DIGIT+) ('.' DIGIT+)? (('+' | '-') DIGIT+ ':' DIGIT+ | 'Z')?
Date ::= '@' DateInner
Time ::= '@' TimeInner
DateTime ::= '@' DateInner 'T' TimeInner
Expression ::= 'Table'
FunctionCall ::= '(' Name (Param | Name ':' 'something')* ')' | Name (Param | Name ':' 'something')*
FunctionDef ::= 'func' SPACE* Name SPACE* Param? SPACE* '->' SPACE* Expression
IntervalLiteral ::= DIGIT+ ('microseconds' | 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years')
CmpOp ::= '==' | '!=' | '~=' | '<' | '>' | '<=' | '>='
MathOp ::= '+' | '-' | '/' | '*'
Param ::= Name | Name '<' ALPHA+ '>'
Range ::= Number '..' Number
String ::= ('"' '*'* '"' | "'" '*'* "'") /* Slicer? */
FString ::= 'f' String /* Slicer? */
RString ::= 'r' String /* Slicer? */
SString ::= 's' String
Number ::= ('+' | '-')? DIGIT ('_'? DIGIT+)* ('e' DIGIT+)?
Assignment ::= 'let' SPACE* '=' SPACE* Expression
/* Slicer ::= '[' Number (':' Number)? ']' */
  1. Copy the EBNF grammar above
  2. Go to https://bottlecaps.de/rr
  3. Click on the Edit Grammar tab
  4. Paste the EBNF grammar
  5. Click on the View Diagram tab

Now you see some pretty diagrams which you can also download.

Note: the diagram is very far from truthful!

@max-sixty
Copy link
Member

Cool @vanillajonathan ! If it's possible to make that accurate we could add it to the repo. It would need to be maintained.

Otherwise we'll have your initial attempt for future travelers as a starting point, still useful.

@vanillajonathan
Copy link
Collaborator Author

vanillajonathan commented Feb 14, 2023

It would be possible to make it accurate, but I am not all too familiar with the PRQL grammar and no PRQL specification exists, furthermore this is the first time I try to write EBNF so I have no experience with that. Yes, it would need to be maintained as the language evolves. Maybe someone else have a better understanding of PRQL and EBNF than me.

Some issues with the above EBNF grammar.

  • Many of the classes are declared but not referenced from anywhere.
  • The Date class only handles date or time, but not date and time, and it only handles one date and one time format.
  • The FunctionDef class doesn't handle multi-line functions.
  • Might need some class for the switch in PRQL.
  • I am unsure if SPACE is a good name or if it should be SP.
  • I am unsure if "*" is a good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants