Builtin Grammars

These grammars are currently shipped with the project.

SQL

Basic SQL as it is teached in most schools, no support for all sorts of imperative constructs.

grammar "sql" {
  typedef "sql"."query" ::= querySelect | queryDelete
  node "sql"."querySelect" {
    container vertical {
      children sequence "select" ::= select
      children sequence "from" ::= from
      children sequence "where" ::= where?
      children sequence "groupBy" ::= groupBy?
      children sequence "orderBy" ::= orderBy?
    }
  }
  node "sql"."select" {
    container horizontal {
      "SELECT"
      children sequence "distinct" ::= distinct?
      container horizontal {
        children allowed "columns" ::= (expression* & starOperator?)
      }
    }
  }
  node "sql"."distinct" {
    "DISTINCT"
  }
  node "sql"."from" {
    "FROM"
    children sequence "tables", between: "," ::= tableIntroduction+
    container vertical {
      children sequence "joins" ::= join*
    }
  }
  node "sql"."tableIntroduction" {
    prop "name" { string }
  }
  typedef "sql"."join" ::= crossJoin | innerJoinUsing | innerJoinOn
  node "sql"."crossJoin" {
    children sequence "table" ::= tableIntroduction
  }
  node "sql"."innerJoinUsing" {
    "INNER JOIN"
    children sequence "table" ::= tableIntroduction
    "USING"
    children sequence "using" ::= expression
  }
  typedef "sql"."expression" ::= columnName | binaryExpression | constant | parameter | functionCall | parentheses
  node "sql"."columnName" {
    prop "refTableName" { string }
    terminal "dot" "."
    prop "columnName" { string }
  }
  node "sql"."binaryExpression" {
    children sequence "lhs" ::= expression
    children sequence "operator" ::= relationalOperator
    children sequence "rhs" ::= expression
  }
  node "sql"."relationalOperator" {
    prop "operator" { string enum "<" "<=" "=" "<>" ">=" ">" "LIKE" "NOT LIKE" }
  }
  node "sql"."constant" {
    prop "value" { string }
  }
  node "sql"."parameter" {
    terminal "colon" ":"
    prop "name" { string }
  }
  node "sql"."functionCall" {
    prop "name" { string }
    terminal "paren-open" "("
    children sequence "distinct" ::= distinct?
    children sequence "arguments", between: "," ::= expression*
    terminal "paren-close" ")"
  }
  node "sql"."parentheses" {
    terminal "parenOpen" "("
    children sequence "expression" ::= expression
    terminal "parenClose" ")"
  }
  node "sql"."innerJoinOn" {
    "INNER JOIN"
    children sequence "table" ::= tableIntroduction
    "ON"
    children sequence "on" ::= expression
  }
  node "sql"."where" {
    "WHERE"
    children sequence "expressions" ::= expression whereAdditional*
  }
  node "sql"."whereAdditional" {
    prop "operator" { string enum "AND" "OR" }
    children sequence "expression" ::= expression
  }
  node "sql"."groupBy" {
    "GROUP BY"
    children allowed "expressions", between: "," ::= expression+
  }
  node "sql"."orderBy" {
    "ORDER BY"
    children allowed "expressions" ::= (expression* & sortOrder*)+
  }
  node "sql"."queryDelete" {
    children sequence "delete" ::= delete
    children sequence "from" ::= from
    children sequence "where" ::= where?
  }
  node "sql"."delete" {
    "DELETE"
  }
  node "sql"."sortOrder" {
    children sequence "expression" ::= expression
    prop "order" { string enum "ASC" "DESC" }
  }
  node "sql"."starOperator" {
    "*"
  }
}

Trucklino Program

The “Truck Programming Language”, first described in the Bachelors Thesis of Sebastian Popp.

grammar "trucklino-program" {
  node "trucklino_program"."program" {
    container vertical {
      children sequence "procedures" ::= procedureDeclaration*
      children sequence "main" ::= statement*
    }
  }
  node "trucklino_program"."procedureDeclaration" {
    container horizontal {
      terminal "function" "function "
      prop "name" { string }
      terminal "parenOpen" "("
      children sequence "arguments" ::= procedureParameter*
      terminal "parenClose" ")"
      terminal "bodyOpen" " {"
    }
    container vertical {
      children sequence "body" ::= statement*
    }
    container horizontal {
      terminal "bodyClose" "}"
    }
  }
  node "trucklino_program"."procedureParameter" {
    prop "name" { string }
  }
  typedef "trucklino_program"."statement" ::= procedureCall | if | loopFor | loopWhile
  node "trucklino_program"."procedureCall" {
    prop "name" { string }
    terminal "parenOpen" "("
    children sequence "arguments" ::= booleanExpression*
    terminal "parenClose" ")"
  }
  typedef "trucklino_program"."booleanExpression" ::= sensor | negateExpression | booleanBinaryExpression | booleanConstant
  node "trucklino_program"."sensor" {
    prop "type" { string enum "lightIsRed" "lightIsGreen" "canGoStraight" "canTurnLeft" "canTurnRight" "canLoad" "canUnload" "isOnTarget" "isSolved" }
  }
  node "trucklino_program"."negateExpression" {
    container horizontal {
      terminal "not" "(NOT "
      children sequence "expr" ::= booleanExpression
      terminal "close" ")"
    }
  }
  node "trucklino_program"."booleanBinaryExpression" {
    container horizontal {
      terminal "open" "("
      children sequence "lhs" ::= booleanExpression
      terminal "spaceBefore" " "
      children sequence "operator" ::= relationalOperator
      terminal "spaceAfter" " "
      children sequence "rhs" ::= booleanExpression
      terminal "close" ")"
    }
  }
  node "trucklino_program"."relationalOperator" {
    prop "operator" { string enum "AND" "OR" }
  }
  node "trucklino_program"."booleanConstant" {
    prop "value" { string enum "true" "false" }
  }
  node "trucklino_program"."if" {
    container horizontal {
      terminal "if" "if"
      terminal "parenOpen" " ("
      container horizontal {
        children sequence "pred" ::= booleanExpression
      }
      terminal "parenClose" ")"
      terminal "bodyOpen" " {"
    }
    container vertical {
      children sequence "body" ::= statement*
    }
    container vertical {
      terminal "bodyClose" "}"
      children sequence "elseIf" ::= ifElseIf*
      children sequence "else" ::= ifElse?
    }
  }
  node "trucklino_program"."ifElseIf" {
    container horizontal {
      terminal "elseIf" "else if"
      terminal "parenOpen" " ("
      children sequence "pred" ::= booleanExpression
      terminal "parenClose" ")"
      terminal "bodyOpen" " {"
    }
    container vertical {
      children sequence "body" ::= statement*
      terminal "bodyClose" "}"
    }
  }
  node "trucklino_program"."ifElse" {
    container horizontal {
      terminal "else" "else"
      terminal "bodyOpen" " {"
    }
    container vertical {
      children sequence "body" ::= statement*
      terminal "bodyClose" "}"
    }
  }
  node "trucklino_program"."loopFor" {
    container horizontal {
      terminal "for" "for"
      terminal "parenOpen" " ("
      prop "times" { integer ≥ 0 }
      terminal "parenClose" ")"
      terminal "bodyOpen" " {"
    }
    children sequence "body" ::= statement*
    terminal "bodyClose" "}"
  }
  node "trucklino_program"."loopWhile" {
    container horizontal {
      terminal "while" "while"
      terminal "parenOpen" " ("
      children sequence "pred" ::= booleanExpression
      terminal "parenClose" ")"
      terminal "bodyOpen" " {"
    }
    container vertical {
      children sequence "body" ::= statement*
    }
    terminal "bodyClose" "}"
  }
}

JSON

This grammar is based upon the formal grammar definition found at json.org. It mimics the exact same structure but does not bother with whitespace.

grammar "json" {
  typedef "json"."value" ::= string | number | boolean | object | array | null
  node "json"."string" {
    terminal "quot-begin" "\""
    prop "value" { string }
    terminal "quot-end" "\""
  }
  node "json"."number" {
    prop "value" { integer }
  }
  node "json"."boolean" {
    prop "value" { boolean }
  }
  node "json"."object" {
    terminal "object-open" "{"
    children allowed "values", between: "," ::= key-value*
    terminal "object-close" "}"
  }
  node "json"."key-value" {
    children allowed "key" ::= string
    terminal "colon" ":"
    children allowed "value" ::= value
  }
  node "json"."array" {
    terminal "array-open" "["
    children allowed "values", between: "," ::= value*
    terminal "array-close" "]"
  }
  node "json"."null" {
    terminal "value" "null"
  }
}

CSS

Definition of CSS stylesheets, which are basicly a set of rules which in turn are defined by selectors and declarations.

grammar "css" {
  node "css"."document" {
    children allowed "rules" ::= rule+
  }
  node "css"."rule" {
    children sequence "selectors" ::= selector+
    terminal "rule-open" "{"
    children allowed "declarations" ::= declaration+
    terminal "rule-close" "}"
  }
  typedef "css"."selector" ::= selectorType | selectorClass | selectorId | selectorUniversal
  node "css"."selectorType" {
    prop "value" { string }
  }
  node "css"."selectorClass" {
    prop "value" { string }
  }
  node "css"."selectorId" {
    prop "value" { string }
  }
  node "css"."selectorUniversal" {
  }
  node "css"."declaration" {
    children choice "name" ::= propertyName
    terminal "colon" ":"
    children choice "value" ::= exprColor | exprAny
  }
  node "css"."propertyName" {
    prop "name" { string }
  }
  node "css"."exprColor" {
    prop "value" { string }
  }
  node "css"."exprAny" {
    prop "value" { string }
  }
}

Dynamic XML

grammar "dxml" {
  node "dxml"."element" {
    terminal "tag-open-begin" "<"
    prop "name" { string }
    children allowed "attributes" ::= attribute*
    terminal "tag-open-end" ">"
    children allowed "elements" ::= element* & text* & interpolate* & if*
    terminal "tag-close" "<ende/>"
  }
  node "dxml"."attribute" {
    prop "name" { string }
    terminal "equals" "="
    terminal "quot-begin" "\""
    children allowed "value" ::= text* & interpolate*
    terminal "quot-end" "\""
  }
  node "dxml"."text" {
    prop "value" { string }
  }
  node "dxml"."interpolate" {
    children allowed "expr" ::= expr
  }
  typedef "dxml"."expr" ::= exprVar | exprConst | exprBinary
  node "dxml"."exprVar" {
    prop "name" { string }
  }
  node "dxml"."exprConst" {
    prop "name" { string }
  }
  node "dxml"."exprBinary" {
    children allowed "lhs" ::= expr
    children allowed "operator" ::= binaryOperator
    children allowed "rhs" ::= expr
  }
  node "dxml"."binaryOperator" {
    prop "operator" { string }
  }
  node "dxml"."if" {
    children allowed "condition" ::= expr
    children allowed "body" ::= element* & text* & interpolate* & if*
  }
}