1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 18:23:44 +03:00

Add support for float literals and var assignments

This commit is contained in:
joshvera 2016-12-01 15:33:37 -05:00
parent 016b905753
commit e9489780d6
6 changed files with 20 additions and 6 deletions

View File

@ -159,6 +159,8 @@ data Category
| HashSplatParameter
-- | A block parameter, e.g. def foo(&block) in Ruby.
| BlockParameter
-- | A float literal.
| FloatLiteral
deriving (Eq, Generic, Ord, Show)
-- Instances
@ -187,6 +189,7 @@ instance Arbitrary Category where
, pure StringLiteral
, pure IntegerLiteral
, pure NumberLiteral
, pure FloatLiteral
, pure Regex
, pure Return
, pure SymbolLiteral

View File

@ -147,6 +147,7 @@ prefixWithPatch patch constructor = prefixWithThe (patchToPrefix patch)
determiner :: DiffInfo -> Doc
determiner (LeafInfo "number" _ _) = ""
determiner (LeafInfo "integer" _ _) = ""
determiner (LeafInfo "float" _ _) = ""
determiner (LeafInfo "boolean" _ _) = ""
determiner (LeafInfo "begin statement" _ _) = "a"
determiner (LeafInfo "select statement" _ _) = "a"
@ -163,6 +164,7 @@ toLeafInfos BranchInfo{..} = branches >>= toLeafInfos
toLeafInfos HideInfo = []
toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
(LeafInfo "number" termName _) -> squotes $ toDoc termName
(LeafInfo "float" termName _) -> squotes $ toDoc termName
(LeafInfo "integer" termName _) -> squotes $ toDoc termName
(LeafInfo "boolean" termName _) -> squotes $ toDoc termName
(LeafInfo "anonymous function" termName _) -> toDoc termName <+> "function"
@ -361,6 +363,7 @@ instance HasCategory Category where
Identifier -> "identifier"
IntegerLiteral -> "integer"
NumberLiteral -> "number"
FloatLiteral -> "float"
Other s -> s
C.Pair -> "pair"
C.Params -> "params"

View File

@ -44,6 +44,7 @@ termConstructor source sourceSpan name range children = case name of
clauses' <- withDefaultInfo $ S.Indexed clauses
withDefaultInfo $ S.Switch clauses' cases
where isCaseClause = (== Case) . category . extract
"assignment_statement" -> toVarAssignment children
"type_switch_statement" ->
case Prologue.break isCaseClause children of
(clauses, cases) -> do
@ -72,6 +73,7 @@ termConstructor source sourceSpan name range children = case name of
[id] -> S.FunctionCall id []
rest -> S.Error rest
"const_declaration" -> toConsts children
"const_spec" -> toConsts children
"func_literal" -> withDefaultInfo $ case children of
[params, _, body] -> S.AnonymousFunction (toList $ unwrap params) (toList $ unwrap body)
rest -> S.Error rest
@ -124,15 +126,18 @@ termConstructor source sourceSpan name range children = case name of
_ -> withCategory Error (S.Error list)
toConsts constSpecs = do
assignments' <- sequenceA $ toVarAssignment <$> constSpecs
assignments' <- sequenceA $ constSpecToVarAssignment <$> constSpecs
withDefaultInfo (S.Indexed assignments')
toVarAssignment constSpec =
case toList (unwrap constSpec) of
constSpecToVarAssignment = toVarAssignment . toList . unwrap
toVarAssignment = \case
[idList, expressionList] -> do
assignments' <- sequenceA $ zipWith (\id expr -> withDefaultInfo $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList)
assignments' <- sequenceA $ zipWith (\id expr ->
withDefaultInfo $ S.VarAssignment id expr)
(toList $ unwrap idList) (toList $ unwrap expressionList)
withDefaultInfo (S.Indexed assignments')
[idList, _, expressionList] -> do
assignments' <- sequenceA $ zipWith (\id expr -> withDefaultInfo $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList)
assignments' <- sequenceA $ zipWith (\id expr ->
withDefaultInfo $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList)
withDefaultInfo (S.Indexed assignments')
[idList] -> do
varDecls <- mapM (withDefaultInfo . S.VarDecl) (toList $ unwrap idList)
@ -155,6 +160,7 @@ categoryForGoName :: Text -> Category
categoryForGoName = \case
"identifier" -> Identifier
"int_literal" -> NumberLiteral
"float_literal" -> FloatLiteral
"comment" -> Comment
"return_statement" -> Return
"interpreted_string_literal" -> StringLiteral

View File

@ -140,6 +140,7 @@ categoryForJavaScriptProductionName name = case name of
"string" -> StringLiteral
"integer" -> IntegerLiteral
"number" -> NumberLiteral
"float" -> FloatLiteral
"symbol" -> SymbolLiteral
"array" -> ArrayLiteral
"function" -> Function

View File

@ -164,7 +164,7 @@ categoryForRubyName = \case
"elsif_block" -> Elsif
"ensure_block" -> Ensure
"ERROR" -> Error
"float" -> NumberLiteral
"float" -> FloatLiteral
"for_statement" -> For
"formal_parameters" -> Params
"function_call" -> FunctionCall

View File

@ -43,6 +43,7 @@ styleName category = "category-" <> case category of
SymbolLiteral -> "symbol"
IntegerLiteral -> "integer"
NumberLiteral -> "number"
FloatLiteral -> "float"
C.Comment -> "comment"
C.FunctionCall -> "function_call"
C.Function -> "function"