Skip to content

Latest commit

 

History

History
165 lines (142 loc) · 2.74 KB

File metadata and controls

165 lines (142 loc) · 2.74 KB

Core Fennel Syntax

This is a list of all the most important core syntax items this parser produces.

This list contains general structure of the nodes represented with queries.

Note

Some of the nodes were omitted for clarity purposes.

Compounds

  • list :: list literal ()
(list
  open: "("
  call: (_)?
  item: (_)*
  close: ")")
  • sequence :: sequence literal, otherwise known as sequential table []
(sequence
  open: "["
  item: (_)*
  close: "]")
  • table :: table literal {}
(table
  open: "{"
  item: (table_pair
          key: (_)
          value: (_))*
  close: "}")

Primitives

  • string :: either colon string :abc or double quote string "abc"
;; colon string
(string
  open: ":"
  content: (string_content))

;; double quote string
(string
  open: "\""
  content: (string_content
             (escape_sequence)*)
  close: "\"")
  • number :: any valid number
(number)
  • nil :: just nil
(nil)
  • boolean :: either true or false
(boolean
  "true")

(boolean
  "false")

Symbols

  • symbol :: anything that's not explicitly defined in the grammar is a symbol
(symbol)
  • symbol_option :: a symbol that starts with &
(symbol_option)

Multi-symbols

  • symbol_fragment :: same as symbol, but only used in multi-symbols
(symbol_fragment)
  • multi_symbol :: a comma separated mush of symbols a.b.c.d
(multi_symbol
  base: (symbol_fragment)
  ("."
   .
   member: (symbol_fragment))+)
  • multi_symbol_method :: method call a.b.c:deeznuts
(multi_symbol_method
  base: [
    (symbol_fragment)
    (multi_symbol)
  ]
  ":"
  method: (symbol_fragment))

Reader macros

All reader macros do is wrap an S-expression, so their structure is identical.

  • hashfn_reader_macro :: #expr
(hashfn_reader_macro
  macro: "#"
  expression: (_))
  • quote_reader_macro :: 'expr
(quote_reader_macro
  macro: "'"
  expression: (_))
  • quasi_quote_reader_macro :: `expr
(quasi_quote_reader_macro
  macro: "`"
  expression: (_))
  • unquote_reader_macro :: ,expr
(unquote_reader_macro
  macro: ","
  expression: (_))

Misc

  • shebang :: matches #! if it's the very first parsed node
(shebang)
  • comment :: a comment ; comment
(comment
  colons: ";"
  body: (comment_body))

Special cases

  • # :: # is recognized as a reader macro if it's immediately followed by an expression, and a symbol otherwise
;; #hello
(reader_macro
  macro: "#"
  expression: (symbol))

;; (# my-table)
(list
  call: (symbol)
  item: (symbol))