diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 456e43fcd..5c105f47c 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -10,7 +10,7 @@ import Data.Maybe (fromMaybe) import Data.Record import Data.Functor (void) import Data.List.NonEmpty (some1) -import Data.Syntax (postContextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm1) +import Data.Syntax (contextualize, postContextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm1) import qualified Data.Syntax as Syntax import Data.Syntax.Assignment hiding (Assignment, Error) import qualified Data.Syntax.Assignment as Assignment @@ -401,7 +401,7 @@ invert term = makeTerm <$> location <*> fmap Expression.Not term -- | Match a term optionally preceded by comment(s), or a sequence of comments if the term is not present. term :: Assignment -> Assignment -term term = many comment *> term <|> makeTerm1 <$> (Syntax.Context <$> some1 comment <*> emptyTerm) +term term = contextualize comment term <|> makeTerm1 <$> (Syntax.Context <$> some1 comment <*> emptyTerm) -- | Match a series of terms or comments until a delimiter is matched. manyTermsTill :: Show b => Assignment.Assignment [] Grammar Term -> Assignment.Assignment [] Grammar b -> Assignment.Assignment [] Grammar [Term] diff --git a/test/fixtures/ruby/hash.diffA-B.txt b/test/fixtures/ruby/hash.diffA-B.txt index 847e9e8d4..6294f4491 100644 --- a/test/fixtures/ruby/hash.diffA-B.txt +++ b/test/fixtures/ruby/hash.diffA-B.txt @@ -20,12 +20,17 @@ {-(Integer)-})-}) {-(Hash)-} {-(Hash - {-(KeyValue - {-(Identifier)-} - {-(Integer)-})-} - {-(KeyValue - {-(TextElement)-} - {-(Integer)-})-} + {-(Context + {-(Comment)-} + {-(KeyValue + {-(Identifier)-} + {-(Integer)-})-})-} + {-(Context + {-(Comment)-} + {-(Comment)-} + {-(KeyValue + {-(TextElement)-} + {-(Integer)-})-})-} {-(Context {-(Comment)-} {-(Empty)-})-})-} diff --git a/test/fixtures/ruby/hash.diffB-A.txt b/test/fixtures/ruby/hash.diffB-A.txt index 2bb3d4edf..7b1ca75c0 100644 --- a/test/fixtures/ruby/hash.diffB-A.txt +++ b/test/fixtures/ruby/hash.diffB-A.txt @@ -20,12 +20,17 @@ {+(Integer)+})+}) {+(Hash)+} {+(Hash - {+(KeyValue - {+(Identifier)+} - {+(Integer)+})+} - {+(KeyValue - {+(TextElement)+} - {+(Integer)+})+} + {+(Context + {+(Comment)+} + {+(KeyValue + {+(Identifier)+} + {+(Integer)+})+})+} + {+(Context + {+(Comment)+} + {+(Comment)+} + {+(KeyValue + {+(TextElement)+} + {+(Integer)+})+})+} {+(Context {+(Comment)+} {+(Empty)+})+})+} diff --git a/test/fixtures/ruby/hash.parseA.txt b/test/fixtures/ruby/hash.parseA.txt index 34a002740..bcc7e907b 100644 --- a/test/fixtures/ruby/hash.parseA.txt +++ b/test/fixtures/ruby/hash.parseA.txt @@ -14,12 +14,17 @@ (Integer))) (Hash) (Hash - (KeyValue - (Identifier) - (Integer)) - (KeyValue - (TextElement) - (Integer)) + (Context + (Comment) + (KeyValue + (Identifier) + (Integer))) + (Context + (Comment) + (Comment) + (KeyValue + (TextElement) + (Integer))) (Context (Comment) (Empty)))