Skip to content

Notation

This documentation uses Extended Backus-Naur Form (EBNF) to represent the Nite language syntax. EBNF can be hard to read at first, so we recommend giving this page at least a glance before reading the rest of the specification.

Grammar rules

A grammar rule has the form name = definition ;, where name is the name of the rule and definition is the grammar expression the rule matches.

identifier = identifier_start { identifier_continue } ;

The right-hand side is built from the following constructs:

  • Terminals are written in double quotes (e.g. "+") or in rare cases in single quotes (e.g. '"'), and match themselves literally.
  • Nonterminals are written in plain words (e.g. identifier) and match whatever the named rule defines.
  • Concatenation is an expression followed by another expression; both must match in order:

    full_name = name , surname ;
    
  • Alternation is an expression followed by | followed by another expression; either may match:

    integer_literal = decimal_literal | hex_literal | binary_literal ;
    
  • Optional is an expression wrapped in square brackets; it may match or be skipped:

    numeric_literal = ( float_literal | integer_literal ) , [ numeric_suffix ] ;
    
  • Repetition is an expression wrapped in curly braces; it matches the expression zero or more times:

    identifier_or_keyword = identifier_start { identifier_continue } ;
    
  • A group is an expression wrapped in parentheses, used to make precedence explicit:

    float_literal  = decimal_literal , "." , decimal_literal
                   | decimal_literal , [ "." , decimal_literal ] , float_exponent ;
    
  • Special sequences are wrapped in question marks and describe a match in words rather than symbols:

    escaped_identifier_character
        = ? any Unicode scalar value except LF, CR, "\", and "`" ? ;
    

Reserved notation

A few characters are used by the notation itself (", |, [, ], {, }, (, ), ,, ?, =, ;). When a grammar needs to match one of these characters literally, it is written inside double quotes, e.g. ",".