prql icon indicating copy to clipboard operation
prql copied to clipboard

Document reserved keywords and built-in functions

Open vanillajonathan opened this issue 3 years ago • 4 comments

Like this:

  • https://docs.python.org/3/reference/lexical_analysis.html#keywords
  • https://docs.python.org/3/library/functions.html

Reserved keywords are:

  • aggregate
  • derive
  • false
  • filter
  • from
  • group
  • join
  • null
  • prql
  • select
  • sort
  • switch
  • take
  • true

Maybe I am missing some?

vanillajonathan avatar Feb 12 '23 15:02 vanillajonathan

One source for them is somewhere like https://github.com/PRQL/prql/blob/main/book/highlight-prql.js.

I'm not sure how to maintain that list though. Unless we can do that well — e.g. we make this list from the compiler itself — I probably wouldn't explicitly list it given it'll fall out of date.

If anyone has thoughts on whether that's possible, that'd be welcome...

max-sixty avatar Feb 12 '23 22:02 max-sixty

I don't know how keep it up to date either, I just figured it would be good to have a reference other than to have to dig into some source file.

From higlight-prql.js

Transforms:

  • aggregate
  • append
  • derive
  • filter
  • from_text
  • from
  • group
  • join
  • select
  • sort
  • take
  • union
  • window

Built-in functions:

  • switch
  • in
  • as

Keywords:

  • func
  • let
  • prql

vanillajonathan avatar Feb 12 '23 23:02 vanillajonathan

To be technically correct, most of the mentioned named are not reserved. Transforms and in and as reside in std module (namespace) which is in the lookup path of the root module, which means they are "always in scope".

So keywords are only:

  • prql
  • func
  • let
  • switch

But even they are parsed as keywords only when used correctly. Otherwise, they are regular idents:

from invoices
select [prql, switch, let, func]

... which is a thing that we should maybe change.

aljazerzen avatar Feb 13 '23 10:02 aljazerzen

This looks covered by the book now, so it may be ready to close.

  • Reserved keywords: the Keywords section of keywords.md, added in #2995, lists prql, let, into, case, type, enum, func, module, import, internal, true, false and null, and says how to use one as an identifier (backticks). That matches the lexer's KEYWORDS and RESERVED_LITERALS exactly. The same section explains that transforms are ordinary std functions rather than keywords, which was @aljazerzen's point above.
  • Built-in functions: the standard library page includes the full std.prql source, so the list can't fall out of date (the maintenance concern raised earlier).

prql-bot avatar Oct 28 '26 06:10 prql-bot