@ Definitions and specifiers
module DefinitionsAndSpecifiers {

  @ Abstract type definition
  type T @< Abstract type definition

  @ Array definition
  array A = [10] U32 default 0 format "{} counts" @< Array definition

  @ Component definition
  active component C {

    type T

    array A = [3] U32

    struct S {
      x: [3] U32
      y: F32
      z: string
    }

    enum E {
      X
      Y
      Z
    }

    @ Command specifier
    async command C(
                     a: U32
                     b: F32
                   ) \
      opcode 0x00 \
      priority 10 \
      assert @< Command specifier

    @ Parameter specifier
    param P: U32 default 0 id 0x00 \
      set opcode 0x01 \
      save opcode 0x02 @< Parameter specifier

    @ General port instance specifier
    sync input port p1: [10] P \
      priority 10 \
      assert @< General port instance specifier

    @ Special port instance specifier
    command recv port cmdIn @< Special port instance specifier

    output port p2: [10] P

    @ Port matching specifier
    match p1 with p2 @< Port matching specifier

    @ Telemetry channel specifier
    telemetry T: U32 id 0x00 update on change \
      format "{} s" \
      low {
        red 0
        orange 1
        yellow 2
      } \
      high {
        yellow 10
        orange 11
        red 12
      } @< Telemetry channel specifier

    @ Event specifier
    event E(
             a: U32
             b: F32
           ) \
      severity activity low \
      id 0x00 \
      format "{} counts" \
      throttle 10 @< Event specifier

    @ Internal port specifier
    internal port I(
                     a: U32
                     b: F32
                   ) \
      priority 10 \
      assert @< Internal port specifier

  } @< Component definition

  @ Simple component instance definition
  instance c1: C1 base id 0x100 @< Simple component instance definition

  @ Component instance definition
  instance c2: C2 base id 0x200 \
    type "T" \
    at "C2.hpp" \
    queue size 100 \
    stack size 1024 \
    priority 10 \
    cpu 0 \
    {
      @ Init specifier
      phase CONSTRUCTION """
                         line 1
                           line 2
                         line 3
                         """ @< Init specifier
    } @< Component instance definition

  @ Constant definition
  constant x = 0 @< Constant definition

  @ Enum definition
  enum E: I32 {
    @ X
    X = 1 @< X
    @ Y
    Y = 2 @< Y
  } @< Enum definition

  @ Module definition
  module M {

    constant x = 0

  } @< Module definition

  @ Included constant
  constant x = 0 @< Included constant

  @ Port definition
  port P(
          a: U32
          b: F32
        ) -> U32 @< Port definition

  @ Struct definition
  struct S {
    @ x
    x: U32 format "{} s" @< x
    @ y
    y: F32 format "{} m/s" @< y
  } @< Struct definition

  @ Topology definition
  topology T {

    @ Public instance specifier
    instance i1 @< Public instance specifier

    @ Private instance specifier
    private instance i2 @< Private instance specifier

    @ Direct connection graph specifier
    connections C {
      i1.p[0] -> i2.p[1]
    } @< Direct connection graph specifier

    @ Graph pattern specifier
    command connections instance i1 {
      i2
      i3
      i4
    } @< Graph pattern specifier

    @ Topology import specifier
    import T1 @< Topology import specifier

  } @< Topology definition

  @ Location specifier
  locate instance i at "instances.fpp" @< Location specifier

} @< Definitions and specifiers

@ Type names
module TypeNames {

  array typeNameU32 = [10] U32

  array typeNameF32 = [10] F32

  array typeNameBool = [10] bool

  array typeNameString = [10] string size 256

  array typeNameQID = [10] a.b.c

} @< Type names

@ Expressions
module Expressions {

  @ Arithmetic
  constant arithExp = 1 + 2 * 3 - -4 * 5 + 6 @< Arithmetic

  @ Array
  constant arrayExp = [
                        1
                        2
                        3
                      ] @< Array

  @ Boolean literal
  constant booleanLiteralExp = true @< Boolean literal

  @ Dot
  constant dotExp = a.b.c @< Dot

  @ FP literal
  constant fpLiteralExp = 0.1234 @< FP literal

  @ Identifier
  constant identExp = x @< Identifier

  @ Int literal
  constant intLiteralExp = 1234 @< Int literal

  @ Paren
  constant parenExp = (1 + 2) * 3 @< Paren

  @ String literal single
  constant stringLiteralSingleExp = "This is a string." @< String literal single

  @ String literal multi
  constant stringLiteralMultExp = """
                                  line 1
                                  line 2
                                  line 3
                                  """ @< String literal multi

  @ Struct
  constant structExp = {
                         a = 1
                         b = 2
                         c = 3
                       } @< Struct

} @< Expressions
