mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Work on Ruby method tokenizing
This commit is contained in:
parent
51d3422191
commit
c622251f56
@ -9,6 +9,7 @@ import qualified Data.Set as Set
|
|||||||
import Diffing.Algorithm
|
import Diffing.Algorithm
|
||||||
import Prologue
|
import Prologue
|
||||||
import Proto3.Suite.Class
|
import Proto3.Suite.Class
|
||||||
|
import Reprinting.Tokenize
|
||||||
|
|
||||||
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
||||||
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, ToJSONFields1, Named1, Message1)
|
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, ToJSONFields1, Named1, Message1)
|
||||||
@ -58,6 +59,14 @@ instance Evaluatable Method where
|
|||||||
pure (Rval addr)
|
pure (Rval addr)
|
||||||
where paramNames = foldMap (maybeToList . declaredName . subterm)
|
where paramNames = foldMap (maybeToList . declaredName . subterm)
|
||||||
|
|
||||||
|
instance Tokenize Method where
|
||||||
|
tokenize Method{..} = within TMethod $ do
|
||||||
|
yield TOpen
|
||||||
|
methodName
|
||||||
|
within TParams $ surround_ (sep_ methodParameters)
|
||||||
|
methodBody
|
||||||
|
yield TClose
|
||||||
|
|
||||||
instance Declarations1 Method where
|
instance Declarations1 Method where
|
||||||
liftDeclaredName declaredName = declaredName . methodName
|
liftDeclaredName declaredName = declaredName . methodName
|
||||||
|
|
||||||
|
@ -13,18 +13,24 @@ translatingRuby = flattened <~ auto step where
|
|||||||
|
|
||||||
step :: Splice -> Seq Splice
|
step :: Splice -> Seq Splice
|
||||||
step s@(Unhandled el cs) = case (el, cs) of
|
step s@(Unhandled el cs) = case (el, cs) of
|
||||||
(Open, (Declaration DeclMethod):_) -> emit "def" <> directive Space
|
(TOpen, TMethod:_) -> emit "def" <> layout Space
|
||||||
(Close, (Declaration DeclMethod):_) -> emit "end"
|
(TClose, TMethod:_) -> emit "end"
|
||||||
(Open, (List:(Declaration DeclMethod):_)) -> emit "("
|
|
||||||
(Close, (List:(Declaration DeclMethod):_)) -> emit ")"
|
|
||||||
|
|
||||||
(Open, Imperative:xs) -> stimesMonoid (n xs) (directives [HardWrap, Indent])
|
(TOpen, TParams:TMethod:_) -> emit "("
|
||||||
(Separator, Imperative:xs) -> stimesMonoid (n xs) (directives [HardWrap, Indent])
|
(TSep, TParams:TMethod:_) -> emit "," <> layout Space
|
||||||
(Close, Imperative:_) -> directive HardWrap
|
(TClose, TParams:TMethod:_) -> emit ")"
|
||||||
|
|
||||||
|
(TOpen, Imperative:xs) -> indented (n xs)
|
||||||
|
(TSep, Imperative:xs) -> indented (n xs)
|
||||||
|
(TClose, Imperative:_) -> layout HardWrap
|
||||||
|
|
||||||
|
-- (TOpen, TComment:_) -> layout HardWrap
|
||||||
|
-- (TSep, TComment:_) -> layout HardWrap
|
||||||
|
|
||||||
_ -> pure s
|
_ -> pure s
|
||||||
|
|
||||||
where
|
where
|
||||||
|
indented times = stimesMonoid times (layouts [HardWrap, Indent])
|
||||||
emit = splice el cs
|
emit = splice el cs
|
||||||
n = length . filter (== Imperative)
|
n = length . filter (== Imperative)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user