diff --git a/src/Data/Syntax/Literal.hs b/src/Data/Syntax/Literal.hs index 40346d8c0..5d88152aa 100644 --- a/src/Data/Syntax/Literal.hs +++ b/src/Data/Syntax/Literal.hs @@ -95,9 +95,14 @@ newtype Symbol a = Symbol { symbolContent :: ByteString } instance Eq1 Symbol where liftEq = genericLiftEq instance Show1 Symbol where liftShowsPrec = genericLiftShowsPrec +newtype Regex a = Regex { regexContent :: ByteString } + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 Regex where liftEq = genericLiftEq +instance Show1 Regex where liftShowsPrec = genericLiftShowsPrec + -- TODO: Heredoc-style string literals? -- TODO: Character literals. --- TODO: Regular expressions. -- Collections diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 205c0d00e..8efd8c538 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -49,6 +49,7 @@ type Syntax = '[ , Literal.KeyValue , Literal.Null , Literal.Rational + , Literal.Regex , Literal.String , Literal.Symbol , Literal.TextElement @@ -171,7 +172,7 @@ literal = <|> makeTerm <$> symbol Subshell <*> (Literal.TextElement <$> source) <|> makeTerm <$> symbol String <*> (Literal.TextElement <$> source) <|> makeTerm <$> symbol ChainedString <*> children (many (term (makeTerm <$> symbol String <*> (Literal.TextElement <$> source)))) - <|> makeTerm <$> symbol Regex <*> (Literal.TextElement <$> source) + <|> makeTerm <$> symbol Regex <*> (Literal.Regex <$> source) <|> makeTerm <$> symbol Symbol <*> (Literal.Symbol <$> source) heredoc :: Assignment diff --git a/test/fixtures/ruby/regex.diffA-B.txt b/test/fixtures/ruby/regex.diffA-B.txt index fb3fb0954..732d2e573 100644 --- a/test/fixtures/ruby/regex.diffA-B.txt +++ b/test/fixtures/ruby/regex.diffA-B.txt @@ -1,4 +1,4 @@ (Program -{ (Regex) -->(Regex) } -{+(Regex)+}) +{+(Regex)+} +{+(Regex)+} +{-(Regex)-}) diff --git a/test/fixtures/ruby/regex.diffB-A.txt b/test/fixtures/ruby/regex.diffB-A.txt index 0edbcd5e1..cfee1709a 100644 --- a/test/fixtures/ruby/regex.diffB-A.txt +++ b/test/fixtures/ruby/regex.diffB-A.txt @@ -1,4 +1,4 @@ (Program -{ (Regex) -->(Regex) } +{+(Regex)+} +{-(Regex)-} {-(Regex)-})