1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Remove term

This commit is contained in:
Rick Winfrey 2017-11-20 16:40:07 -08:00
parent a971450c57
commit 7b335fb2f1

View File

@ -239,7 +239,7 @@ literalValue :: Assignment
literalValue = makeTerm <$> symbol LiteralValue <*> children (many expression)
compositeLiteral :: Assignment
compositeLiteral = makeTerm <$> symbol CompositeLiteral <*> children (Literal.Composite <$> term expression <*> term expression)
compositeLiteral = makeTerm <$> symbol CompositeLiteral <*> children (Literal.Composite <$> expression <*> expression)
intLiteral :: Assignment
intLiteral = makeTerm <$> symbol IntLiteral <*> (Literal.Integer <$> source)
@ -254,7 +254,8 @@ typeIdentifier :: Assignment
typeIdentifier = makeTerm <$> symbol TypeIdentifier <*> (Syntax.Identifier <$> source)
identifier :: Assignment
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier <$> source)
identifier = makeTerm <$> symbol Identifier <*> (Syntax.Identifier <$> source)
<|> makeTerm <$> symbol Identifier' <*> (Syntax.Identifier <$> source)
fieldIdentifier :: Assignment
fieldIdentifier = makeTerm <$> symbol FieldIdentifier <*> (Syntax.Identifier <$> source)
@ -263,7 +264,7 @@ packageIdentifier :: Assignment
packageIdentifier = makeTerm <$> symbol PackageIdentifier <*> (Syntax.Identifier <$> source)
parenthesizedType :: Assignment
parenthesizedType = makeTerm <$> symbol Grammar.ParenthesizedType <*> children (Go.Syntax.ParenthesizedType <$> term expression)
parenthesizedType = makeTerm <$> symbol Grammar.ParenthesizedType <*> children (Go.Syntax.ParenthesizedType <$> expression)
interpretedStringLiteral :: Assignment
interpretedStringLiteral = makeTerm <$> symbol InterpretedStringLiteral <*> (Literal.TextElement <$> source)
@ -278,26 +279,24 @@ runeLiteral = makeTerm <$> symbol Grammar.RuneLiteral <*> (Go.Syntax.RuneLiteral
-- Primitive Types
qualifiedType :: Assignment
qualifiedType = makeTerm <$> symbol QualifiedType <*> children (Expression.MemberAccess <$> term expression <*> term expression)
qualifiedType = makeTerm <$> symbol QualifiedType <*> children (Expression.MemberAccess <$> expression <*> expression)
arrayType :: Assignment
arrayType = makeTerm <$> symbol ArrayType <*> children (Type.Array . Just <$> term expression <*> (term expression <|> term arrayType))
arrayType = makeTerm <$> symbol ArrayType <*> children (Type.Array . Just <$> expression <*> (expression <|> arrayType))
implicitLengthArrayType :: Assignment
implicitLengthArrayType = makeTerm <$> symbol ImplicitLengthArrayType <*> children (Type.Array Nothing <$> term expression)
implicitLengthArrayType = makeTerm <$> symbol ImplicitLengthArrayType <*> children (Type.Array Nothing <$> expression)
functionType :: Assignment
functionType = makeTerm <$> symbol FunctionType <*> children (Type.Function <$> manyTerm parameters <*> term returnType)
where
returnType = symbol Parameters *> children expressions <|> term expression <|> emptyTerm
functionType = makeTerm <$> symbol FunctionType <*> children (Type.Function <$> many parameters <*> (expression <|> emptyTerm))
sliceType :: Assignment
sliceType = makeTerm <$> symbol SliceType <*> children (Type.Slice <$> term expression)
sliceType = makeTerm <$> symbol SliceType <*> children (Type.Slice <$> expression)
channelType :: Assignment
channelType = (makeTerm <$> symbol ChannelType <*> children (token AnonLAngleMinus *> token AnonChan *> (Type.ReceiveChannel <$> term expression)))
<|> (makeTerm <$> symbol ChannelType <*> children (token AnonChan *> token AnonLAngleMinus *> (Type.SendChannel <$> term expression)))
<|> (makeTerm <$> symbol ChannelType <*> children (token AnonChan *> (Type.BiDirectionalChannel <$> term expression)))
channelType = (makeTerm <$> symbol ChannelType <*> children (token AnonLAngleMinus *> token AnonChan *> (Type.ReceiveChannel <$> expression)))
<|> (makeTerm <$> symbol ChannelType <*> children (token AnonChan *> token AnonLAngleMinus *> (Type.SendChannel <$> expression)))
<|> (makeTerm <$> symbol ChannelType <*> children (token AnonChan *> (Type.BiDirectionalChannel <$> expression)))
structType :: Assignment
structType = makeTerm <$> symbol StructType <*> children (Declaration.Constructor <$> emptyTerm <*> many expression)
@ -306,13 +305,13 @@ interfaceType :: Assignment
interfaceType = makeTerm <$> symbol InterfaceType <*> children (Type.Interface <$> many expression)
mapType :: Assignment
mapType = handleError $ makeTerm <$> symbol MapType <*> children (Type.Map <$> term expression <*> term expression)
mapType = makeTerm <$> symbol MapType <*> children (Type.Map <$> expression <*> expression)
pointerType :: Assignment
pointerType = handleError $ makeTerm <$> symbol PointerType <*> children (Type.Pointer <$> term expression)
pointerType = makeTerm <$> symbol PointerType <*> children (Type.Pointer <$> expression)
fieldDeclaration :: Assignment
fieldDeclaration = mkFieldDeclarationWithTag <$> symbol FieldDeclaration <*> children ((,,) <$> (manyTermsTill expression (void (symbol TypeIdentifier)) <|> (manyTerm expression)) <*> optional (term expression) <*> optional (term expression))
fieldDeclaration = mkFieldDeclarationWithTag <$> symbol FieldDeclaration <*> children ((,,) <$> (manyTermsTill expression (void (symbol TypeIdentifier)) <|> (many expression)) <*> optional expression <*> optional expression)
where
mkFieldDeclarationWithTag loc (fields, (Just type'), (Just tag)) = makeTerm loc $ Go.Syntax.Field [type', tag] (makeTerm loc fields) --Type.Annotation (makeTerm loc (Type.Annotation (makeTerm loc fields) type')) tag
mkFieldDeclarationWithTag loc (fields, (Just type'), Nothing) = makeTerm loc $ Go.Syntax.Field [type'] (makeTerm loc fields)
@ -323,37 +322,37 @@ fieldDeclaration = mkFieldDeclarationWithTag <$> symbol FieldDeclaration <*> ch
-- Type Declarations
channelTypeDeclaration :: Assignment
channelTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term channelType)
channelTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> channelType)
functionTypeDeclaration :: Assignment
functionTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term functionType)
functionTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> functionType)
interfaceTypeDeclaration :: Assignment
interfaceTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term interfaceType)
interfaceTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> interfaceType)
mapTypeDeclaration :: Assignment
mapTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term mapType)
mapTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> mapType)
structTypeDeclaration :: Assignment
structTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term structType)
structTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> structType)
qualifiedTypeDeclaration :: Assignment
qualifiedTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term qualifiedType)
qualifiedTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> qualifiedType)
arrayTypeDeclaration :: Assignment
arrayTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term arrayType)
arrayTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> arrayType)
sliceTypeDeclaration :: Assignment
sliceTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term sliceType)
sliceTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> sliceType)
pointerTypeDeclaration :: Assignment
pointerTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term pointerType)
pointerTypeDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> pointerType)
typeAlias :: Assignment
typeAlias = makeTerm <$> symbol TypeAlias <*> children (Type.Alias <$> term expression <*> term expression)
typeAlias = makeTerm <$> symbol TypeAlias <*> children (Type.Alias <$> expression <*> expression)
typeIdentifierDeclaration :: Assignment
typeIdentifierDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> term typeIdentifier <*> term expression)
typeIdentifierDeclaration = makeTerm <$> symbol TypeSpec <*> children (Type.Annotation <$> typeIdentifier <*> expression)
typeDeclaration :: Assignment
typeDeclaration = makeTerm <$> symbol TypeDeclaration <*> children (many ( arrayTypeDeclaration
@ -375,38 +374,38 @@ indexExpression :: Assignment
indexExpression = makeTerm <$> symbol IndexExpression <*> children (Expression.Subscript <$> expression <*> many expression)
sliceExpression :: Assignment
sliceExpression = makeTerm <$> symbol SliceExpression <*> children ( (Go.Syntax.Slice <$> term expression <*> term expression <*> term expression <*> term expression)
<|> (Go.Syntax.Slice <$> term expression <*> emptyTerm <* symbol AnonColon <*> term expression <* symbol AnonColon <*> term expression)
<|> (Go.Syntax.Slice <$> term expression <*> emptyTerm <* symbol AnonColon <*> term expression <*> emptyTerm)
<|> (Go.Syntax.Slice <$> term expression <*> term expression <*> term expression <*> emptyTerm)
<|> (Go.Syntax.Slice <$> term expression <*> term expression <*> emptyTerm <*> emptyTerm)
<|> (Go.Syntax.Slice <$> term expression <*> emptyTerm <*> emptyTerm <*> emptyTerm))
sliceExpression = makeTerm <$> symbol SliceExpression <*> children ( (Go.Syntax.Slice <$> expression <*> expression <*> expression <*> expression)
<|> (Go.Syntax.Slice <$> expression <*> emptyTerm <* symbol AnonColon <*> expression <* symbol AnonColon <*> expression)
<|> (Go.Syntax.Slice <$> expression <*> emptyTerm <* symbol AnonColon <*> expression <*> emptyTerm)
<|> (Go.Syntax.Slice <$> expression <*> expression <*> expression <*> emptyTerm)
<|> (Go.Syntax.Slice <$> expression <*> expression <*> emptyTerm <*> emptyTerm)
<|> (Go.Syntax.Slice <$> expression <*> emptyTerm <*> emptyTerm <*> emptyTerm))
parenthesizedExpression :: Assignment
parenthesizedExpression = symbol ParenthesizedExpression *> children expressions
selectorExpression :: Assignment
selectorExpression = makeTerm <$> symbol SelectorExpression <*> children (Expression.MemberAccess <$> term expression <*> term expression)
selectorExpression = makeTerm <$> symbol SelectorExpression <*> children (Expression.MemberAccess <$> expression <*> expression)
typeAssertion :: Assignment
typeAssertion = makeTerm <$> symbol TypeAssertionExpression <*> children (Go.Syntax.TypeAssertion <$> term expression <*> term expression)
typeAssertion = makeTerm <$> symbol TypeAssertionExpression <*> children (Go.Syntax.TypeAssertion <$> expression <*> expression)
typeConversion :: Assignment
typeConversion = makeTerm <$> symbol TypeConversionExpression <*> children (Go.Syntax.TypeConversion <$> term expression <*> term expression)
typeConversion = makeTerm <$> symbol TypeConversionExpression <*> children (Go.Syntax.TypeConversion <$> expression <*> expression)
unaryExpression :: Assignment
unaryExpression = symbol UnaryExpression >>= \ location -> (notExpression location) <|> (unaryMinus location) <|> unaryPlus <|> unaryAmpersand <|> unaryReceive <|> unaryPointer <|> unaryComplement
where
notExpression location = makeTerm location . Expression.Not <$> children (symbol AnonBang *> term expression)
unaryMinus location = makeTerm location . Expression.Negate <$> children (symbol AnonMinus *> term expression)
notExpression location = makeTerm location . Expression.Not <$> children (symbol AnonBang *> expression)
unaryMinus location = makeTerm location . Expression.Negate <$> children (symbol AnonMinus *> expression)
unaryPlus = children (symbol AnonPlus *> expression)
unaryAmpersand = children (makeTerm <$> symbol AnonAmpersand <*> (Literal.Reference <$> term expression))
unaryReceive = children (makeTerm <$> symbol AnonLAngleMinus <*> (Go.Syntax.Receive <$> emptyTerm <*> term expression))
unaryPointer = children (makeTerm <$> symbol AnonStar <*> (Literal.Pointer <$> term expression))
unaryComplement = children (makeTerm <$> symbol AnonCaret <*> (Expression.Complement <$> term expression))
unaryAmpersand = children (makeTerm <$> symbol AnonAmpersand <*> (Literal.Reference <$> expression))
unaryReceive = children (makeTerm <$> symbol AnonLAngleMinus <*> (Go.Syntax.Receive <$> emptyTerm <*> expression))
unaryPointer = children (makeTerm <$> symbol AnonStar <*> (Literal.Pointer <$> expression))
unaryComplement = children (makeTerm <$> symbol AnonCaret <*> (Expression.Complement <$> expression))
binaryExpression :: Assignment
binaryExpression = makeTerm' <$> symbol BinaryExpression <*> children (infixTerm expression (contextualize comment expression)
binaryExpression = makeTerm' <$> symbol BinaryExpression <*> children (infixTerm expression expression
[ (inj .) . Expression.Plus <$ symbol AnonPlus
, (inj .) . Expression.Minus <$ symbol AnonMinus
, (inj .) . Expression.Times <$ symbol AnonStar
@ -443,13 +442,13 @@ defaultExpressionCase :: Assignment
defaultExpressionCase = makeTerm <$> symbol DefaultCase <*> (Go.Syntax.DefaultPattern <$ source <*> (expressions <|> emptyTerm))
expressionCaseClause :: Assignment
expressionCaseClause = symbol ExpressionCaseClause *> children (term (expressionCase <|> defaultExpressionCase))
expressionCaseClause = symbol ExpressionCaseClause *> children (expressionCase <|> defaultExpressionCase)
expressionSwitchStatement :: Assignment
expressionSwitchStatement = makeTerm <$> symbol ExpressionSwitchStatement <*> children (Statement.Match <$> (makeTerm <$> location <*> manyTermsTill expression (void (symbol ExpressionCaseClause)) <|> emptyTerm) <*> expressions)
typeSwitchStatement :: Assignment
typeSwitchStatement = makeTerm <$> symbol TypeSwitchStatement <*> children (Go.Syntax.TypeSwitch <$> term _typeSwitchSubject <*> expressions)
typeSwitchStatement = makeTerm <$> symbol TypeSwitchStatement <*> children (Go.Syntax.TypeSwitch <$> _typeSwitchSubject <*> expressions)
where
_typeSwitchSubject = makeTerm <$> location <*> manyTermsTill expression (void (symbol TypeCaseClause))
@ -457,7 +456,7 @@ typeSwitchGuard :: Assignment
typeSwitchGuard = makeTerm <$> symbol Grammar.TypeSwitchGuard <*> children (Go.Syntax.TypeSwitchGuard <$> expressions)
typeCaseClause :: Assignment
typeCaseClause = makeTerm <$> symbol TypeCaseClause <*> children (Statement.Pattern <$> term expression <*> expressions)
typeCaseClause = makeTerm <$> symbol TypeCaseClause <*> children (Statement.Pattern <$> expression <*> expressions)
typeCase :: Assignment
typeCase = symbol TypeCase *> children expressions
@ -466,10 +465,10 @@ fallThroughStatement :: Assignment
fallThroughStatement = makeTerm <$> symbol FallthroughStatement <*> (Statement.Pattern <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)) <*> emptyTerm)
variadicArgument :: Assignment
variadicArgument = makeTerm <$> symbol VariadicArgument <*> children (Go.Syntax.Variadic <$> pure [] <*> term expression)
variadicArgument = makeTerm <$> symbol VariadicArgument <*> children (Go.Syntax.Variadic <$> pure [] <*> expression)
callExpression :: Assignment
callExpression = makeTerm <$> symbol CallExpression <*> children (Expression.Call <$> pure [] <*> term expression <*> manyTerm expression <*> emptyTerm)
callExpression = makeTerm <$> symbol CallExpression <*> children (Expression.Call <$> pure [] <*> expression <*> many expression <*> emptyTerm)
varDeclaration :: Assignment
varDeclaration = (symbol ConstDeclaration <|> symbol VarDeclaration) *> children expressions
@ -477,22 +476,22 @@ varDeclaration = (symbol ConstDeclaration <|> symbol VarDeclaration) *> children
varSpecification :: Assignment
varSpecification = makeTerm <$> (symbol ConstSpec <|> symbol VarSpec) <*> children (Statement.Assignment <$> pure [] <*> (annotatedLHS <|> identifiers) <*> expressions)
where
annotatedLHS = makeTerm <$> location <*> (Type.Annotation <$> (makeTerm <$> location <*> (manyTermsTill identifier (void (symbol TypeIdentifier)))) <*> term expression)
annotatedLHS = makeTerm <$> location <*> (Type.Annotation <$> (makeTerm <$> location <*> (manyTermsTill identifier (void (symbol TypeIdentifier)))) <*> expression)
expressionList :: Assignment
expressionList = symbol ExpressionList *> children expressions
functionDeclaration :: Assignment
functionDeclaration = mkTypedFunctionDeclaration <$> symbol FunctionDeclaration <*> children ((,,,) <$> term expression <*> manyTerm parameters <*> optional (term types <|> term identifier <|> term returnParameters) <*> optional (term block))
<|> mkTypedFunctionLiteral <$> symbol FuncLiteral <*> children ((,,,) <$> emptyTerm <*> manyTerm parameters <*> optional (term types <|> term identifier <|> term returnParameters) <*> term block)
functionDeclaration = mkTypedFunctionDeclaration <$> symbol FunctionDeclaration <*> children ((,,,) <$> expression <*> many parameters <*> optional (types <|> identifier <|> returnParameters) <*> optional block)
<|> mkTypedFunctionLiteral <$> symbol FuncLiteral <*> children ((,,,) <$> emptyTerm <*> many parameters <*> optional (types <|> identifier <|> returnParameters) <*> block)
where
mkTypedFunctionDeclaration loc (name', params', types', block') = makeTerm loc (Declaration.Function [(maybe (makeTerm loc Syntax.Empty) id types')] name' params' (maybe (makeTerm loc Syntax.Empty) id block'))
mkTypedFunctionLiteral loc (name', params', types', block') = makeTerm loc (Declaration.Function [(maybe (makeTerm loc Syntax.Empty) id types')] name' params' block')
returnParameters = makeTerm <$> symbol Parameters <*> children (many expression)
variadicParameterDeclaration :: Assignment
variadicParameterDeclaration = mkVariadic <$> symbol VariadicParameterDeclaration <*> children ((,) <$> emptyTerm <*> term expression)
<|> mkVariadic <$> symbol VariadicParameterDeclaration <*> children ((,) <$> term expression <*> term expression)
variadicParameterDeclaration = mkVariadic <$> symbol VariadicParameterDeclaration <*> children ((,) <$> emptyTerm <*> expression)
<|> mkVariadic <$> symbol VariadicParameterDeclaration <*> children ((,) <$> expression <*> expression)
where
mkVariadic loc (identifier', typeIdentifier') = makeTerm loc (Go.Syntax.Variadic [typeIdentifier'] identifier')
@ -509,26 +508,26 @@ parameterDeclaration :: Assignment
parameterDeclaration = makeTerm <$> symbol ParameterDeclaration <*> children (many expression)
methodDeclaration :: Assignment
methodDeclaration = mkTypedMethodDeclaration <$> symbol MethodDeclaration <*> children ((,,,,) <$> term receiver <*> term fieldIdentifier <*> manyTerm parameters <*> term ((makeTerm <$> location <*> (manyTermsTill expression (void (symbol Block)))) <|> emptyTerm) <*> term (block <|> emptyTerm))
methodDeclaration = mkTypedMethodDeclaration <$> symbol MethodDeclaration <*> children ((,,,,) <$> receiver <*> fieldIdentifier <*> many parameters <*> ((makeTerm <$> location <*> (manyTermsTill expression (void (symbol Block)))) <|> emptyTerm) <*> (block <|> emptyTerm))
where
receiver = symbol Parameters *> children ((symbol ParameterDeclaration *> children expressions) <|> expressions)
mkTypedMethodDeclaration loc (receiver', name', parameters', type'', body') = makeTerm loc (Declaration.Method [type''] receiver' name' parameters' body')
methodSpec :: Assignment
methodSpec = mkMethodSpec <$> symbol MethodSpec <*> children ((,,,,) <$> empty <*> term expression <*> term parameters <*> (term expression <|> term parameters <|> term emptyTerm) <*> term empty)
methodSpec = mkMethodSpec <$> symbol MethodSpec <*> children ((,,,,) <$> empty <*> expression <*> parameters <*> (expression <|> parameters <|> emptyTerm) <*> empty)
where
empty = makeTerm <$> location <*> pure Syntax.Empty
mkMethodSpec loc (receiver', name', params, optionaltypeLiteral, body') = makeTerm loc $ Type.Annotation (mkMethod loc receiver' name' params body') optionaltypeLiteral
mkMethod loc empty' name' params empty'' = makeTerm loc $ Declaration.Method [] empty' name' (pure params) empty''
packageClause :: Assignment
packageClause = makeTerm <$> symbol PackageClause <*> children (Declaration.Module <$> term expression <*> pure [])
packageClause = makeTerm <$> symbol PackageClause <*> children (Declaration.Module <$> expression <*> pure [])
-- Statements
assignment' :: Assignment
assignment' = makeTerm' <$> symbol AssignmentStatement <*> children (infixTerm expressionList (term expressionList)
assignment' = makeTerm' <$> symbol AssignmentStatement <*> children (infixTerm expressionList expressionList
[ assign <$ symbol AnonEqual
, augmentedAssign Expression.Plus <$ symbol AnonPlusEqual
, augmentedAssign Expression.Minus <$ symbol AnonMinusEqual
@ -555,76 +554,76 @@ emptyStatement :: Assignment
emptyStatement = makeTerm <$> token EmptyStatement <*> (Statement.NoOp <$> emptyTerm)
shortVarDeclaration :: Assignment
shortVarDeclaration = makeTerm <$> symbol ShortVarDeclaration <*> children (Statement.Assignment <$> pure [] <*> term expression <*> term expression)
shortVarDeclaration = makeTerm <$> symbol ShortVarDeclaration <*> children (Statement.Assignment <$> pure [] <*> expression <*> expression)
sendStatement :: Assignment
sendStatement = makeTerm <$> symbol SendStatement <*> children (Go.Syntax.Send <$> term expression <*> term expression)
sendStatement = makeTerm <$> symbol SendStatement <*> children (Go.Syntax.Send <$> expression <*> expression)
breakStatement :: Assignment
breakStatement = makeTerm <$> symbol BreakStatement <*> children (Statement.Break <$> (term labelName' <|> term emptyTerm))
breakStatement = makeTerm <$> symbol BreakStatement <*> children (Statement.Break <$> (labelName' <|> emptyTerm))
continueStatement :: Assignment
continueStatement = makeTerm <$> symbol ContinueStatement <*> children (Statement.Continue <$> (term labelName' <|> term emptyTerm))
continueStatement = makeTerm <$> symbol ContinueStatement <*> children (Statement.Continue <$> (labelName' <|> emptyTerm))
decStatement :: Assignment
decStatement = makeTerm <$> symbol DecStatement <*> children (Statement.PostDecrement <$> term expression)
decStatement = makeTerm <$> symbol DecStatement <*> children (Statement.PostDecrement <$> expression)
deferStatement :: Assignment
deferStatement = makeTerm <$> symbol DeferStatement <*> children (Go.Syntax.Defer <$> term expression)
deferStatement = makeTerm <$> symbol DeferStatement <*> children (Go.Syntax.Defer <$> expression)
goStatement :: Assignment
goStatement = makeTerm <$> symbol GoStatement <*> children (Go.Syntax.Go <$> term expression)
goStatement = makeTerm <$> symbol GoStatement <*> children (Go.Syntax.Go <$> expression)
gotoStatement :: Assignment
gotoStatement = makeTerm <$> symbol GotoStatement <*> children (Statement.Goto <$> term expression)
gotoStatement = makeTerm <$> symbol GotoStatement <*> children (Statement.Goto <$> expression)
ifStatement :: Assignment
ifStatement = makeTerm <$> symbol IfStatement <*> children (Statement.If <$> (makeTerm <$> location <*> manyTermsTill expression (void (symbol Block))) <*> term expression <*> (term expression <|> term emptyTerm))
ifStatement = makeTerm <$> symbol IfStatement <*> children (Statement.If <$> (makeTerm <$> location <*> manyTermsTill expression (void (symbol Block))) <*> expression <*> (expression <|> emptyTerm))
ifInitializer :: Assignment
ifInitializer = symbol IfInitializer *> children (term expression)
ifInitializer = symbol IfInitializer *> children expression
elseClause :: Assignment
elseClause = symbol ElseClause *> children (term expression)
elseClause = symbol ElseClause *> children expression
forStatement :: Assignment
forStatement = mkForStatement <$> symbol ForStatement <*> children ((,) <$> (forClause <|> rangeClause <|> for <|> emptyClause) <*> term expression)
forStatement = mkForStatement <$> symbol ForStatement <*> children ((,) <$> (forClause <|> rangeClause <|> for <|> emptyClause) <*> expression)
where
mkForStatement loc ((constructor, a, b, c), block') = case (constructor :: [Char]) of
"forEach" -> makeTerm loc $ (Statement.ForEach a b block')
_ -> makeTerm loc $ (Statement.For a b c block')
emptyClause = children (("for",,,) <$> emptyTerm <*> emptyTerm <*> emptyTerm)
rangeClause = symbol RangeClause *> children ( (("forEach",,,) <$> term expression <*> term expression <*> emptyTerm)
<|> (("forEach",,,) <$> term emptyTerm <*> term expression <*> emptyTerm))
forClause = symbol ForClause *> children ( (("for",,,) <$> term expression <*> term expression <*> term expression)
<|> (("for",,,) <$> term expression <*> term expression <*> emptyTerm)
<|> (("for",,,) <$> term expression <*> emptyTerm <*> emptyTerm)
<|> (("for",,,) <$> term emptyTerm <*> emptyTerm <*> emptyTerm))
for = ("for",,,) <$> emptyTerm <*> term expression <*> emptyTerm
rangeClause = symbol RangeClause *> children ( (("forEach",,,) <$> expression <*> expression <*> emptyTerm)
<|> (("forEach",,,) <$> emptyTerm <*> expression <*> emptyTerm))
forClause = symbol ForClause *> children ( (("for",,,) <$> expression <*> expression <*> expression)
<|> (("for",,,) <$> expression <*> expression <*> emptyTerm)
<|> (("for",,,) <$> expression <*> emptyTerm <*> emptyTerm)
<|> (("for",,,) <$> emptyTerm <*> emptyTerm <*> emptyTerm))
for = ("for",,,) <$> emptyTerm <*> expression <*> emptyTerm
incStatement :: Assignment
incStatement = makeTerm <$> symbol IncStatement <*> children (Statement.PostIncrement <$> term expression)
incStatement = makeTerm <$> symbol IncStatement <*> children (Statement.PostIncrement <$> expression)
keyedElement :: Assignment
keyedElement = makeTerm <$> symbol KeyedElement <*> children (Literal.KeyValue <$> term expression <*> term expression)
keyedElement = makeTerm <$> symbol KeyedElement <*> children (Literal.KeyValue <$> expression <*> expression)
labelName' :: Assignment
labelName' = makeTerm <$> symbol LabelName <*> (Syntax.Identifier <$> source)
labelStatement' :: Assignment
labelStatement' = makeTerm <$> symbol LabelStatement <*> children (Go.Syntax.Label <$> term expression <*> (term expression <|> emptyTerm))
labelStatement' = makeTerm <$> symbol LabelStatement <*> children (Go.Syntax.Label <$> expression <*> (expression <|> emptyTerm))
returnStatement :: Assignment
returnStatement = makeTerm <$> symbol ReturnStatement <*> children (Statement.Return <$> (term expression <|> emptyTerm))
returnStatement = makeTerm <$> symbol ReturnStatement <*> children (Statement.Return <$> (expression <|> emptyTerm))
receiveStatement :: Assignment
receiveStatement = makeTerm <$> symbol ReceiveStatement <*> children ( (Go.Syntax.Receive <$> term expression <*> term expression)
<|> (Go.Syntax.Receive <$> emptyTerm <*> term expression))
receiveStatement = makeTerm <$> symbol ReceiveStatement <*> children ( (Go.Syntax.Receive <$> expression <*> expression)
<|> (Go.Syntax.Receive <$> emptyTerm <*> expression))
selectStatement :: Assignment
selectStatement = makeTerm <$> symbol SelectStatement <*> children (Go.Syntax.Select <$> expressions)
communicationClause :: Assignment
communicationClause = makeTerm <$> symbol CommunicationClause <*> children (Statement.Pattern <$> (term communicationCase <|> term defaultCase) <*> expressions)
communicationClause = makeTerm <$> symbol CommunicationClause <*> children (Statement.Pattern <$> (communicationCase <|> defaultCase) <*> expressions)
where
communicationCase = symbol CommunicationCase *> children expression