1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00

Add escape sequences to ruby

This commit is contained in:
joshvera 2018-08-10 12:28:53 -04:00
parent 6566b05d4c
commit fbd464e400
2 changed files with 17 additions and 2 deletions

View File

@ -130,6 +130,17 @@ instance Show1 TextElement where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable TextElement where
eval (TextElement x) = rvalBox (string x)
-- | A sequence of textual contents within a string literal.
newtype EscapeSequence a = EscapeSequence { value :: Text }
deriving (Diffable, Eq, Foldable, Functor, Generic1, Hashable1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)
instance Eq1 EscapeSequence where liftEq = genericLiftEq
instance Ord1 EscapeSequence where liftCompare = genericLiftCompare
instance Show1 EscapeSequence where liftShowsPrec = genericLiftShowsPrec
-- TODO: Implement Eval instance for EscapeSequence
instance Evaluatable EscapeSequence
data Null a = Null
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)

View File

@ -127,6 +127,7 @@ type Syntax = '[
, Ruby.Syntax.Require
, Ruby.Syntax.Send
, []
, Literal.EscapeSequence
]
type Term = Term.Term (Sum Syntax) (Record Location)
@ -270,7 +271,7 @@ literal =
where
string :: Assignment Term
string = makeTerm' <$> (symbol String <|> symbol BareString) <*>
(children (inject . Literal.String <$> some interpolation) <|> inject . Literal.TextElement <$> source)
(children (inject . Literal.String <$> some (interpolation <|> escapeSequence)) <|> inject . Literal.TextElement <$> source)
symbol' :: Assignment Term
symbol' = makeTerm' <$> (symbol Symbol <|> symbol Symbol' <|> symbol BareSymbol) <*>
@ -279,9 +280,12 @@ literal =
interpolation :: Assignment Term
interpolation = makeTerm <$> symbol Interpolation <*> children (Literal.InterpolationElement <$> expression)
escapeSequence :: Assignment Term
escapeSequence = makeTerm <$> symbol EscapeSequence <*> (Literal.EscapeSequence <$> source)
heredoc :: Assignment Term
heredoc = makeTerm <$> symbol HeredocBeginning <*> (Literal.TextElement <$> source)
<|> makeTerm <$> symbol HeredocBody <*> children (some (interpolation <|> heredocEnd))
<|> makeTerm <$> symbol HeredocBody <*> children (some (interpolation <|> escapeSequence <|> heredocEnd))
where heredocEnd = makeTerm <$> symbol HeredocEnd <*> (Literal.TextElement <$> source)
beginBlock :: Assignment Term