From 9618db2cdb36e55dd31f3aeaa8b4a93f52834aad Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 20 Jul 2017 13:52:10 -0700 Subject: [PATCH] Produce program syntaxes (for ruby at least) --- src/Data/Syntax.hs | 6 ++++++ src/Language/Ruby/Syntax.hs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index f972da1f7..66a49114c 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -32,6 +32,12 @@ newtype Identifier a = Identifier ByteString instance Eq1 Identifier where liftEq = genericLiftEq instance Show1 Identifier where liftShowsPrec = genericLiftShowsPrec +newtype Program a = Program [a] + deriving (Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 Program where liftEq = genericLiftEq +instance Show1 Program where liftShowsPrec = genericLiftShowsPrec + -- | Empty syntax, with essentially no-op semantics. -- diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 4ca9cc310..54406c882 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -67,6 +67,7 @@ type Syntax = '[ , Syntax.Empty , Syntax.Error , Syntax.Identifier + , Syntax.Program , [] ] @@ -76,7 +77,9 @@ type Assignment = HasCallStack => Assignment.Assignment (AST Grammar) Grammar Te -- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax. assignment :: Assignment -assignment = makeTerm <$> symbol Program <*> children (many statement) <|> parseError +assignment = + makeTerm <$> symbol Program <*> children (Syntax.Program <$> many statement) + <|> parseError statement :: Assignment statement =