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 Prologue
|
||||
import Proto3.Suite.Class
|
||||
import Reprinting.Tokenize
|
||||
|
||||
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
||||
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, ToJSONFields1, Named1, Message1)
|
||||
@ -58,6 +59,14 @@ instance Evaluatable Method where
|
||||
pure (Rval addr)
|
||||
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
|
||||
liftDeclaredName declaredName = declaredName . methodName
|
||||
|
||||
|
@ -13,18 +13,24 @@ translatingRuby = flattened <~ auto step where
|
||||
|
||||
step :: Splice -> Seq Splice
|
||||
step s@(Unhandled el cs) = case (el, cs) of
|
||||
(Open, (Declaration DeclMethod):_) -> emit "def" <> directive Space
|
||||
(Close, (Declaration DeclMethod):_) -> emit "end"
|
||||
(Open, (List:(Declaration DeclMethod):_)) -> emit "("
|
||||
(Close, (List:(Declaration DeclMethod):_)) -> emit ")"
|
||||
(TOpen, TMethod:_) -> emit "def" <> layout Space
|
||||
(TClose, TMethod:_) -> emit "end"
|
||||
|
||||
(Open, Imperative:xs) -> stimesMonoid (n xs) (directives [HardWrap, Indent])
|
||||
(Separator, Imperative:xs) -> stimesMonoid (n xs) (directives [HardWrap, Indent])
|
||||
(Close, Imperative:_) -> directive HardWrap
|
||||
(TOpen, TParams:TMethod:_) -> emit "("
|
||||
(TSep, TParams:TMethod:_) -> emit "," <> layout Space
|
||||
(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
|
||||
|
||||
where
|
||||
indented times = stimesMonoid times (layouts [HardWrap, Indent])
|
||||
emit = splice el cs
|
||||
n = length . filter (== Imperative)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user