Skip to content

GoPlus Syntax Spec

xushiwei edited this page Jun 18, 2022 · 7 revisions
Operand =
  Ident | BasicLit |
  ParenExpr |
  FuncType | FuncLit |
  CompositeLit | ComprehensionExpr |
  ArrayType | SliceLit |
  StructType | PointerType | InterfaceType | MapType | ChanType

ParenExpr =
  '(' Expr ')'

PrimaryExpr = 
  SelectorExpr | TypeAssertExpr |
  SliceExpr | IndexExpr |
  CallExpr | CommandExpr |
  CompositeLit

SelectorExpr = Operand '.' Ident
TypeAssertExpr = Operand '.' '(' Type ')'
SliceExpr = Operand '[' ... ']'
IndexExpr = Operand '[' ... ']'
CallExpr = Operand '(' Args ')' 
CommandExpr = Operand Args
CompositeLit = Operand '{' Elements '}'

UnaryExpr =
  ('+' | '-' | '!' | '^' | '&' | "<-") UnaryExpr |
  StarExpr |
  ErrWrapExpr

StarExpr = '*' UnaryExpr

ErrWrapExpr =
  PrimaryExpr ('!' | '?' | "?:" UnaryExpr)

BinaryExpr =
  UnaryExpr BinaryOp BinaryExpr

RangeExpr =
  ?BinaryExpr ':' BinaryExpr ?(':' BinaryExpr)

LambdaExpr =
  RangeExpr |
  ?(Ident | tupleExpr) "=>" lambdaExprBody

tupleExpr =
  '(' Idents ')'

lambdaExprBody =
  '(' Exprs ')' |
  '{' ... '}' |
  Expr