Program: OuterStatements ENDMARKER
Action: NAME ('.' NAME | CallArgs)* CallArgs NEWLINE
Atom: NAME | STRING | NUMBER | Set | StructConstructor | ParenthesizedExpression
BinaryExpression: Operand (Operator Operand)*
CallArgs: '(' [Expressions] ')'
ConstDef: 'const' NAME [':' TypeExpression] '=' Expression NEWLINE
DocString: STRING NEWLINE
Expression: BinaryExpression ['?' BinaryExpression ':' BinaryExpression]
Expressions: Expression (',' Expression)*
ForBlock: 'for' NAME 'in' Expression ':' NEWLINE INDENT InnerStatements DEDENT
ForClause: 'for' NAME 'in' Expression
FormalArg: NAME ':' TypeExpression ['=' Expression]
FormalArgs: '(' [FormalArg (',' FormalArg)*] ')'
FromName: QualName | RelativeFromName
FunOrField: Atom Suffix*
FuncDef: 'func' NAME FormalArgs ':' TypeExpression ':' NEWLINE INDENT [DocString] InnerStatements DEDENT
IfBlock: 'if' Expression ':' NEWLINE INDENT InnerStatements DEDENT ( 'elif' Expression ':' NEWLINE INDENT InnerStatements DEDENT )* [ 'else' ':' NEWLINE INDENT InnerStatements DEDENT ]
IfClause: 'if' Expression
Import: ['from' FromName] 'import' ImportName (',' ImportName)* NEWLINE
ImportName: NAME ['as' NAME]
InnerStatement: ForBlock | IfBlock | Action | LetDef
InnerStatements: ReturnStatement | InnerStatement+ [ReturnStatement] | Pass
InterfaceAttrDef: NAME [FormalArgs] ':' TypeExpression NEWLINE
InterfaceAttrDefs: InterfaceAttrDef+
InterfaceDef: 'interface' NAME ':' NEWLINE INDENT [DocString] (InterfaceAttrDefs | 'pass' NEWLINE) DEDENT
KeyValuePair: NAME '=' Expression
KeyValuePairs: KeyValuePair (',' KeyValuePair)*
LetDef: 'let' NAME [':' TypeExpression] '=' Expression NEWLINE
Operand: FunOrField | UnaryExpression
Operator: '**' | '*' | '/' | '+' | '-' | '&' | '^' | '|' | ['not'] 'in' | '==' | '<' | '>' | '!=' | '<=' | '>=' | 'and' | 'or'
OuterStatement: Import | TypeDef | ConstDef | InterfaceDef | StructDef | ProcDef | FuncDef
OuterStatements: [DocString] OuterStatement+
ParenthesizedExpression: '(' Expression ')'
Pass: 'pass' NEWLINE
ProcDef: 'proc' NAME FormalArgs ':' NEWLINE INDENT [DocString] InnerStatements DEDENT
QualName: NAME ('.' NAME)*
RelativeFromName: '.' [QualName]
ReturnStatement: 'return' [Expression] NEWLINE
Set: '{' [SetBody] '}'
SetBody: Expression ForClause [IfClause] | Expression (',' Expression)*
SetType: 'set' 'of' TypeExpression
StructAttrDef: NAME ':' TypeExpression ['=' Expression] NEWLINE
StructAttrDefs: StructAttrDef+
StructConstructor: 'new' QualName '(' [KeyValuePairs] ')'
StructDef: 'struct' NAME ':' NEWLINE INDENT [DocString] (StructAttrDefs | 'pass' NEWLINE) DEDENT
Suffix: '.' NAME | CallArgs
TypeDef: 'type' NAME '=' TypeExpression NEWLINE
TypeExpression: QualName | SetType
UnaryExpression: UnaryOperator Operand
UnaryOperator: 'not' | '-'
