mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Add support for float literals and var assignments
This commit is contained in:
parent
016b905753
commit
e9489780d6
@ -159,6 +159,8 @@ data Category
|
|||||||
| HashSplatParameter
|
| HashSplatParameter
|
||||||
-- | A block parameter, e.g. def foo(&block) in Ruby.
|
-- | A block parameter, e.g. def foo(&block) in Ruby.
|
||||||
| BlockParameter
|
| BlockParameter
|
||||||
|
-- | A float literal.
|
||||||
|
| FloatLiteral
|
||||||
deriving (Eq, Generic, Ord, Show)
|
deriving (Eq, Generic, Ord, Show)
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
@ -187,6 +189,7 @@ instance Arbitrary Category where
|
|||||||
, pure StringLiteral
|
, pure StringLiteral
|
||||||
, pure IntegerLiteral
|
, pure IntegerLiteral
|
||||||
, pure NumberLiteral
|
, pure NumberLiteral
|
||||||
|
, pure FloatLiteral
|
||||||
, pure Regex
|
, pure Regex
|
||||||
, pure Return
|
, pure Return
|
||||||
, pure SymbolLiteral
|
, pure SymbolLiteral
|
||||||
|
@ -147,6 +147,7 @@ prefixWithPatch patch constructor = prefixWithThe (patchToPrefix patch)
|
|||||||
determiner :: DiffInfo -> Doc
|
determiner :: DiffInfo -> Doc
|
||||||
determiner (LeafInfo "number" _ _) = ""
|
determiner (LeafInfo "number" _ _) = ""
|
||||||
determiner (LeafInfo "integer" _ _) = ""
|
determiner (LeafInfo "integer" _ _) = ""
|
||||||
|
determiner (LeafInfo "float" _ _) = ""
|
||||||
determiner (LeafInfo "boolean" _ _) = ""
|
determiner (LeafInfo "boolean" _ _) = ""
|
||||||
determiner (LeafInfo "begin statement" _ _) = "a"
|
determiner (LeafInfo "begin statement" _ _) = "a"
|
||||||
determiner (LeafInfo "select statement" _ _) = "a"
|
determiner (LeafInfo "select statement" _ _) = "a"
|
||||||
@ -163,6 +164,7 @@ toLeafInfos BranchInfo{..} = branches >>= toLeafInfos
|
|||||||
toLeafInfos HideInfo = []
|
toLeafInfos HideInfo = []
|
||||||
toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
|
toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
|
||||||
(LeafInfo "number" termName _) -> squotes $ toDoc termName
|
(LeafInfo "number" termName _) -> squotes $ toDoc termName
|
||||||
|
(LeafInfo "float" termName _) -> squotes $ toDoc termName
|
||||||
(LeafInfo "integer" termName _) -> squotes $ toDoc termName
|
(LeafInfo "integer" termName _) -> squotes $ toDoc termName
|
||||||
(LeafInfo "boolean" termName _) -> squotes $ toDoc termName
|
(LeafInfo "boolean" termName _) -> squotes $ toDoc termName
|
||||||
(LeafInfo "anonymous function" termName _) -> toDoc termName <+> "function"
|
(LeafInfo "anonymous function" termName _) -> toDoc termName <+> "function"
|
||||||
@ -361,6 +363,7 @@ instance HasCategory Category where
|
|||||||
Identifier -> "identifier"
|
Identifier -> "identifier"
|
||||||
IntegerLiteral -> "integer"
|
IntegerLiteral -> "integer"
|
||||||
NumberLiteral -> "number"
|
NumberLiteral -> "number"
|
||||||
|
FloatLiteral -> "float"
|
||||||
Other s -> s
|
Other s -> s
|
||||||
C.Pair -> "pair"
|
C.Pair -> "pair"
|
||||||
C.Params -> "params"
|
C.Params -> "params"
|
||||||
|
@ -44,6 +44,7 @@ termConstructor source sourceSpan name range children = case name of
|
|||||||
clauses' <- withDefaultInfo $ S.Indexed clauses
|
clauses' <- withDefaultInfo $ S.Indexed clauses
|
||||||
withDefaultInfo $ S.Switch clauses' cases
|
withDefaultInfo $ S.Switch clauses' cases
|
||||||
where isCaseClause = (== Case) . category . extract
|
where isCaseClause = (== Case) . category . extract
|
||||||
|
"assignment_statement" -> toVarAssignment children
|
||||||
"type_switch_statement" ->
|
"type_switch_statement" ->
|
||||||
case Prologue.break isCaseClause children of
|
case Prologue.break isCaseClause children of
|
||||||
(clauses, cases) -> do
|
(clauses, cases) -> do
|
||||||
@ -72,6 +73,7 @@ termConstructor source sourceSpan name range children = case name of
|
|||||||
[id] -> S.FunctionCall id []
|
[id] -> S.FunctionCall id []
|
||||||
rest -> S.Error rest
|
rest -> S.Error rest
|
||||||
"const_declaration" -> toConsts children
|
"const_declaration" -> toConsts children
|
||||||
|
"const_spec" -> toConsts children
|
||||||
"func_literal" -> withDefaultInfo $ case children of
|
"func_literal" -> withDefaultInfo $ case children of
|
||||||
[params, _, body] -> S.AnonymousFunction (toList $ unwrap params) (toList $ unwrap body)
|
[params, _, body] -> S.AnonymousFunction (toList $ unwrap params) (toList $ unwrap body)
|
||||||
rest -> S.Error rest
|
rest -> S.Error rest
|
||||||
@ -124,15 +126,18 @@ termConstructor source sourceSpan name range children = case name of
|
|||||||
_ -> withCategory Error (S.Error list)
|
_ -> withCategory Error (S.Error list)
|
||||||
|
|
||||||
toConsts constSpecs = do
|
toConsts constSpecs = do
|
||||||
assignments' <- sequenceA $ toVarAssignment <$> constSpecs
|
assignments' <- sequenceA $ constSpecToVarAssignment <$> constSpecs
|
||||||
withDefaultInfo (S.Indexed assignments')
|
withDefaultInfo (S.Indexed assignments')
|
||||||
toVarAssignment constSpec =
|
constSpecToVarAssignment = toVarAssignment . toList . unwrap
|
||||||
case toList (unwrap constSpec) of
|
toVarAssignment = \case
|
||||||
[idList, expressionList] -> do
|
[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')
|
withDefaultInfo (S.Indexed assignments')
|
||||||
[idList, _, expressionList] -> do
|
[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')
|
withDefaultInfo (S.Indexed assignments')
|
||||||
[idList] -> do
|
[idList] -> do
|
||||||
varDecls <- mapM (withDefaultInfo . S.VarDecl) (toList $ unwrap idList)
|
varDecls <- mapM (withDefaultInfo . S.VarDecl) (toList $ unwrap idList)
|
||||||
@ -155,6 +160,7 @@ categoryForGoName :: Text -> Category
|
|||||||
categoryForGoName = \case
|
categoryForGoName = \case
|
||||||
"identifier" -> Identifier
|
"identifier" -> Identifier
|
||||||
"int_literal" -> NumberLiteral
|
"int_literal" -> NumberLiteral
|
||||||
|
"float_literal" -> FloatLiteral
|
||||||
"comment" -> Comment
|
"comment" -> Comment
|
||||||
"return_statement" -> Return
|
"return_statement" -> Return
|
||||||
"interpreted_string_literal" -> StringLiteral
|
"interpreted_string_literal" -> StringLiteral
|
||||||
|
@ -140,6 +140,7 @@ categoryForJavaScriptProductionName name = case name of
|
|||||||
"string" -> StringLiteral
|
"string" -> StringLiteral
|
||||||
"integer" -> IntegerLiteral
|
"integer" -> IntegerLiteral
|
||||||
"number" -> NumberLiteral
|
"number" -> NumberLiteral
|
||||||
|
"float" -> FloatLiteral
|
||||||
"symbol" -> SymbolLiteral
|
"symbol" -> SymbolLiteral
|
||||||
"array" -> ArrayLiteral
|
"array" -> ArrayLiteral
|
||||||
"function" -> Function
|
"function" -> Function
|
||||||
|
@ -164,7 +164,7 @@ categoryForRubyName = \case
|
|||||||
"elsif_block" -> Elsif
|
"elsif_block" -> Elsif
|
||||||
"ensure_block" -> Ensure
|
"ensure_block" -> Ensure
|
||||||
"ERROR" -> Error
|
"ERROR" -> Error
|
||||||
"float" -> NumberLiteral
|
"float" -> FloatLiteral
|
||||||
"for_statement" -> For
|
"for_statement" -> For
|
||||||
"formal_parameters" -> Params
|
"formal_parameters" -> Params
|
||||||
"function_call" -> FunctionCall
|
"function_call" -> FunctionCall
|
||||||
|
@ -43,6 +43,7 @@ styleName category = "category-" <> case category of
|
|||||||
SymbolLiteral -> "symbol"
|
SymbolLiteral -> "symbol"
|
||||||
IntegerLiteral -> "integer"
|
IntegerLiteral -> "integer"
|
||||||
NumberLiteral -> "number"
|
NumberLiteral -> "number"
|
||||||
|
FloatLiteral -> "float"
|
||||||
C.Comment -> "comment"
|
C.Comment -> "comment"
|
||||||
C.FunctionCall -> "function_call"
|
C.FunctionCall -> "function_call"
|
||||||
C.Function -> "function"
|
C.Function -> "function"
|
||||||
|
Loading…
Reference in New Issue
Block a user