From fa274a5a41d313207652d1e3e44768e1929754c9 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 30 Oct 2017 17:50:16 -0700 Subject: [PATCH] Assign switch statements --- src/Language/Go/Assignment.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Language/Go/Assignment.hs b/src/Language/Go/Assignment.hs index 5091e7877..67d2c033f 100644 --- a/src/Language/Go/Assignment.hs +++ b/src/Language/Go/Assignment.hs @@ -40,6 +40,7 @@ type Syntax = , Statement.PostDecrement , Statement.PostIncrement , Expression.MemberAccess + , Go.Syntax.DefaultPattern , Go.Syntax.Variadic , Literal.Array , Literal.Channel @@ -52,6 +53,8 @@ type Syntax = , Statement.Break , Statement.Goto , Statement.If + , Statement.Match + , Statement.Pattern , Statement.Pointer , Statement.Reference , Statement.Return @@ -98,7 +101,9 @@ expressionChoices = , decStatement , element , elseClause + , expressionCaseClause , expressionList + , expressionSwitchStatement , fieldDeclaration , fieldIdentifier , functionDeclaration @@ -311,6 +316,20 @@ binaryExpression = makeTerm' <$> symbol BinaryExpression <*> children (infixTerm block :: Assignment block = symbol Block *> children expressions +expressionCase :: Assignment +expressionCase = makeTerm <$> symbol ExpressionCase <*> (Statement.Pattern <$> children expressions <*> expressions) + +defaultExpressionCase :: Assignment +defaultExpressionCase = makeTerm <$> symbol DefaultExpressionCase <* source <*> (Go.Syntax.DefaultPattern <$> expressions) + +expressionCaseClause :: Assignment +expressionCaseClause = symbol ExpressionCaseClause *> children (expressionCase <|> defaultExpressionCase) + +expressionSwitchStatement :: Assignment +expressionSwitchStatement = makeTerm <$> symbol ExpressionSwitchStatement <*> children (Statement.Match <$> (expression <|> emptyTerm) <*> (expressionCaseClauses <|> emptyTerm)) + where + expressionCaseClauses = makeTerm <$> location <*> many expressionCaseClause + variadicArgument :: Assignment variadicArgument = makeTerm <$> symbol VariadicArgument <*> children (Go.Syntax.Variadic <$> pure [] <*> expression)