From cec63c69aa270cac4180eb5080b0d487919732d9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 7 Apr 2017 14:29:48 -0400 Subject: [PATCH] Pull the Ruby rules out to the top level. --- src/Language/Ruby/Syntax.hs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index a8c5c4c6f..af128eee1 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -35,14 +35,26 @@ data Grammar = Program | Uninterpreted | BeginBlock | EndBlock | Undef | Alias | -- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax. assignment :: Assignment Grammar (Program Syntax (Maybe a)) assignment = foldr (>>) (pure Nothing) <$ rule Program <*> children (many declaration) - where declaration = comment <|> class' <|> method - class' = wrapU <$ rule Class - <*> children (Declaration.Class <$> constant <*> pure [] <*> declaration) - constant = wrapU . Syntax.Identifier <$ rule Constant <*> content - identifier = wrapU . Syntax.Identifier <$ rule Identifier <*> content - method = wrapU <$ rule Method - <*> children (Declaration.Method <$> identifier <*> pure [] <*> statement) - statement = expr + +declaration :: Assignment Grammar (Program Syntax a) +declaration = comment <|> class' <|> method + +class' :: Assignment Grammar (Program Syntax a) +class' = wrapU <$ rule Class + <*> children (Declaration.Class <$> constant <*> pure [] <*> declaration) + +constant :: Assignment Grammar (Program Syntax a) +constant = wrapU . Syntax.Identifier <$ rule Constant <*> content + +identifier :: Assignment Grammar (Program Syntax a) +identifier = wrapU . Syntax.Identifier <$ rule Identifier <*> content + +method :: Assignment Grammar (Program Syntax a) +method = wrapU <$ rule Method + <*> children (Declaration.Method <$> identifier <*> pure [] <*> statement) + +statement :: Assignment Grammar (Program Syntax a) +statement = expr comment :: Assignment Grammar (Program Syntax a) comment = wrapU . Comment.Comment <$ rule Comment <*> content