Advertisement
Guest User

corona.bnf

a guest
Jun 8th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BNF 6.49 KB | None | 0 0
  1. {
  2. psiClassPrefix = "Corona"
  3.  
  4. elementTypeHolderClass="com.gameforge.idea.Corona.lang.parser.CoronaElementTypes"
  5. elementTypeClass="com.gameforge.idea.Corona.lang.lexer.CoronaElementType"
  6. tokenTypeClass="com.gameforge.idea.Corona.lang.lexer.CoronaElementType"
  7.  
  8. implements = "com.gameforge.idea.Corona.lang.psi.CoronaPsiElement"
  9. extends = "com.gameforge.idea.Corona.lang.psi.impl.CoronaPsiElementImpl"
  10.  
  11. psiVisitorName="CoronaVisitor"
  12. psiPackage="com.gameforge.idea.Corona.lang.psi"
  13. psiImplPackage="com.gameforge.idea.Corona.lang.psi.impl"
  14.  
  15. }
  16.  
  17. // Finding 1: there has to be an empty rule, because Grammar-kit, for whatever reason, deletes the first rule.
  18. // unused ::= String
  19.  
  20. // Finding 2: apparently, if you put an empty rule in here, the code won't work. The first rule is not created as a PSI Object but still used as the root File node by the parser
  21. Root ::= Block
  22.  
  23. Block ::= BlockStatement | BlockLastStatement
  24.  
  25. private BlockStatement ::= Statements Statements* [LastStatement]
  26. private BlockLastStatement ::= Statements* LastStatement
  27.  
  28. //#################################################################
  29. //#################### Statements & Variables #####################
  30. //#################################################################
  31.  
  32. Statements ::= (FunctionDeclaration | Assignment | expressionStatement | Declaration | ForLoop | WhileLoop | RepeatLoop | If | ClassOOP) [LineEnding]
  33.  
  34. LastStatement ::= returnState | break
  35. private returnState ::= return (Statements | Expression) //{pin=1}
  36.  
  37. ChainedCall ::= (ChainedFunctionCall | ChainedVariableCall) index
  38. ChainedVariableCall ::= PreCall Variable
  39. ChainedFunctionCall ::= PreCall FunctionCall
  40. private call ::= (funcCall | varCall) index
  41.  
  42. PreChainedVariable ::= (ClassVariable | simpleVarChain) FunctionCallToken
  43. private simpleVarChain ::= Identifier (FunctionCallToken Identifier &FunctionCallToken)*
  44. private index ::= ('[' Expression ']')*
  45.  
  46. Variable ::= (Identifier | ThisIdentifier) index !('(' | FunctionCallToken | ',')
  47.  
  48. ClassVariable ::= ClassField [PreChainedVariable]
  49.  
  50. Declaration ::= [local] (VariableList | varCall)
  51.  
  52. TableConstructor ::= '{' [ExpressionList] '}'
  53.  
  54. Assignment ::= Declaration '=' (ExpressionList | Expression)
  55.  
  56. VariableList ::= varCall ',' varCall (',' varCall)* //{recoverWhile="Assignment"}
  57. private varCall ::= ChainedVariableCall | Variable
  58. private funcCall ::= ChainedFunctionCall | FunctionCall
  59.  
  60. ThisIdentifier ::= this {
  61.    mixin="com.gameforge.idea.Corona.lang.psi.impl.CoronaPsiNamedElementImpl"
  62.    methods=[ getIdentifier="ThisIdentifier" getNameIdentifier="ThisIdentifier" getName setName]
  63. }
  64.  
  65. Identifier ::= Name {
  66.    mixin="com.gameforge.idea.Corona.lang.psi.impl.CoronaPsiNamedElementImpl"
  67.    methods=[ getIdentifier="Identifier" getNameIdentifier="Identifier" getName setName]
  68. }
  69. ClassIdentifier ::= Class {
  70.    mixin="com.gameforge.idea.Corona.lang.psi.impl.CoronaPsiNamedElementImpl"
  71.    methods=[ getIdentifier="ClassIdentifier" getNameIdentifier="ClassIdentifier" getName setName]
  72. }
  73.  
  74. //####################################################
  75. //#################### Functions #####################
  76. //####################################################
  77. private functionBracketsOpen ::= '(' | '{'
  78. private functionBracketsClose ::= ')' | '}'
  79.  
  80. IdentifierList ::= Identifier (',' Identifier)*
  81.  
  82. ParameterList ::= IdentifierList [',' '...'] | '...'
  83.  
  84. FunctionDeclaration ::= [local] function functionName functionBody end
  85.  
  86. AnonymousFunction ::= [local] function functionBody end
  87.  
  88. private functionParameter ::= '(' [ParameterList] ')' | '(' ThisIdentifier ')'
  89.  
  90. private functionBody ::= functionParameter [Block] {pin=1}
  91.  
  92. private functionName ::= [PreChainedVariable] Identifier
  93.  
  94. //private preFuncName ::= ClassField [simpleVarChain] FunctionCallToken
  95.  
  96. FunctionCall ::= Identifier functionBracketsOpen [ExpressionList] functionBracketsClose
  97.  
  98. ForLoop ::= for LoopExpression LoopBody
  99.  
  100. WhileLoop ::= while Expression LoopBody
  101.  
  102. RepeatLoop ::= repeat [Block] until Expression
  103.  
  104. LoopBody ::= do [Block] end
  105.  
  106. LoopExpression ::= Identifier '=' Expression ',' Expression [',' Expression] | IdentifierList in ExpressionList
  107.  
  108. //####################################################
  109. //################### expression #####################
  110. //####################################################
  111. ExpressionList ::= Expression ',' Expression (',' Expression)*
  112.  
  113. Expression ::=  (ExpressionValues | AnonymousFunction | RequireBlock | Assignment | PrefixExpression | TableConstructor | UnaryOperator Expression | boolExpression) [OperatorExpression]
  114. private expressionStatement ::= RequireStatement | funcCall index | TableConstructor | boolExpression | UnaryOperator Expression
  115.  
  116. OperatorExpression ::= BinaryOperator Expression
  117.  
  118. PrefixExpression ::= ChainedCall | '(' Expression ')'
  119.  
  120. If ::= if Expression then Block (elseif Expression then Block)* [else Block] end
  121.  
  122. RequireBlock ::= require '(' requireParameter ')'
  123.  
  124. private requireParameter ::= (ExpressionValues | ChainedCall) ['..' (ExpressionValues | ChainedCall)]
  125.  
  126. PreCall ::= preCallPart preCallPart*
  127.  
  128. private preCallPart ::= (PreChainedVariable | FunctionCall FunctionCallToken | '(' Expression ')' FunctionCallToken | Variable FunctionCallToken)
  129.  
  130. private boolExpression ::= call and boolExpressionReturnValue or boolExpressionReturnValue
  131. private boolExpressionReturnValue ::= (call | ExpressionValues)
  132. //####################################################
  133. //###################### Class #######################
  134. //####################################################
  135. private visibilityTable ::= '.' Visibility  {pin=1}
  136. Visibility ::= public | private | protected
  137.  
  138. ClassField ::= ThisIdentifier [visibilityTable]
  139.  
  140. RequireStatement ::= (Identifier | ClassIdentifier) '=' RequireBlock
  141.  
  142. ClassOOP ::= ClassIdentifier ':' (ClassCreateFunction | ClassExtendFunction)
  143.  
  144. ClassCreateFunction ::= create '(' AnonymousFunction ')'
  145.  
  146. ClassExtendFunction ::= extend '(' ClassParent ',' AnonymousFunction ')'
  147.  
  148. ClassParent ::= Path | ChainedCall
  149.  
  150. //####################################################
  151. //###################### Token #######################
  152. //####################################################
  153. private LineEnding ::= ';'
  154.  
  155. BinaryOperator ::= '+' | '-' | '*' | '/' | '^' | '%' | '..' | '<' | '<=' | '>' | '>=' | '==' | '~=' | and | or
  156.  
  157. UnaryOperator ::= '-' | not | '#'
  158.  
  159. FieldSeparator ::= ',' | ';'
  160.  
  161. FunctionCallToken ::= '.' | ':'
  162.  
  163. ExpressionValues ::= nil | false | true | Number | String String* | '...' | Path
  164.  
  165. Path ::= '"' String ('.' String)* '"'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement