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" {
    children sequence "select" ::= select
    children sequence "from" ::= from
    children sequence "where" ::= where?
    children sequence "groupBy" ::= groupBy?
    children sequence "orderBy" ::= orderBy?
  }
  node "sql"."select" {
    terminal "keyword" "SELECT"
    children allowed "columns" ::= (expression* & starOperator?)
  }
  node "sql"."from" {
    terminal "keyword" "FROM"
    children sequence "tables", between: "," ::= tableIntroduction+
    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" {
    terminal "keyword" "INNER JOIN"
    children sequence "table" ::= tableIntroduction
    terminal "keywordUsing" "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 "arguments", between: "," ::= expression*
    terminal "paren-close" ")"
  }
  node "sql"."parentheses" {
    terminal "parenOpen" "("
    children sequence "expression" ::= expression
    terminal "parenClose" ")"
  }
  node "sql"."innerJoinOn" {
    terminal "keyword" "INNER JOIN"
    children sequence "table" ::= tableIntroduction
    terminal "keywordOn" "ON"
    children sequence "on" ::= expression
  }
  node "sql"."where" {
    terminal "keyword" "WHERE"
    children sequence "expressions" ::= expression whereAdditional*
  }
  node "sql"."whereAdditional" {
    prop "operator" { string enum "AND" "OR" }
    children sequence "expression" ::= expression
  }
  node "sql"."groupBy" {
    terminal "keyword" "GROUP BY"
    children allowed "expressions", between: "," ::= expression+
  }
  node "sql"."orderBy" {
    terminal "keyword" "ORDER BY"
    children allowed "expressions", between: "," ::= expression+
  }
  node "sql"."queryDelete" {
    children sequence "delete" ::= delete
    children sequence "from" ::= from
    children sequence "where" ::= where?
  }
  node "sql"."delete" {
    terminal "keyword" "DELETE"
  }
  node "sql"."sortOrder" {
    prop "order" { string enum "ASC" "DESC" }
  }
  node "sql"."starOperator" {
    terminal "star" "*"
  }
}

Trucklino Program

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

grammar "trucklino-program" {
  node "trucklino_program"."program" {
    children sequence "procedures" ::= procedureDeclaration*
    children sequence "main" ::= statement*
  }
  node "trucklino_program"."procedureDeclaration" {
    terminal "function" "function "
    prop "name" { string }
    terminal "parenOpen" "("
    children sequence "arguments" ::= procedureParameter*
    terminal "parenClose" ")"
    terminal "bodyOpen" " {"
    children sequence "body" ::= statement*
    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" {
    terminal "not" "(NOT "
    children sequence "expr" ::= booleanExpression
    terminal "close" ")"
  }
  node "trucklino_program"."booleanBinaryExpression" {
    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" {
    terminal "if" "if"
    terminal "parenOpen" " ("
    children sequence "pred" ::= booleanExpression
    terminal "parenClose" ")"
    terminal "bodyOpen" " {"
    children sequence "body" ::= statement*
    terminal "bodyClose" "}"
    children sequence "elseIf" ::= ifElseIf*
    children sequence "else" ::= ifElse?
  }
  node "trucklino_program"."ifElseIf" {
    terminal "elseIf" "else if"
    terminal "parenOpen" " ("
    children sequence "pred" ::= booleanExpression
    terminal "parenClose" ")"
    terminal "bodyOpen" " {"
    children sequence "body" ::= statement*
    terminal "bodyClose" "}"
  }
  node "trucklino_program"."ifElse" {
    terminal "else" "else"
    terminal "bodyOpen" " {"
    children sequence "body" ::= statement*
    terminal "bodyClose" "}"
  }
  node "trucklino_program"."loopFor" {
    terminal "for" "for"
    terminal "parenOpen" " ("
    prop "times" { integer ≥ 0 }
    terminal "parenClose" ")"
    terminal "bodyOpen" " {"
    children sequence "body" ::= statement*
    terminal "bodyClose" "}"
  }
  node "trucklino_program"."loopWhile" {
    terminal "while" "while"
    terminal "parenOpen" " ("
    children sequence "pred" ::= booleanExpression
    terminal "parenClose" ")"
    terminal "bodyOpen" " {"
    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*
  }
}