From 376de45263e3d51ff3323d5a9755127b2edeb880 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 6 Apr 2017 09:40:47 -0400 Subject: [PATCH] Take a stab at assigning class declarations. --- src/Language/Ruby/Syntax.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 896d3e52c..0b630574d 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -52,13 +52,15 @@ type Program = Freer -- | Statically-known rules corresponding to symbols in the grammar. -data Grammar = Program | Uninterpreted | BeginBlock | EndBlock | Undef | Alias | Comment | True' | False' | Return | Yield | Break | Next | Redo | Retry | IfModifier | UnlessModifier | WhileModifier | UntilModifier | RescueModifier | While | Until | For | Do | Case | When | Pattern | If | Unless | Elsif | Else | Begin | Ensure | Rescue | Exceptions | ExceptionVariable | ElementReference | ScopeResolution | Call | MethodCall | ArgumentList | ArgumentListWithParens | SplatArgument | HashSplatArgument | BlockArgument | Class +data Grammar = Program | Uninterpreted | BeginBlock | EndBlock | Undef | Alias | Comment | True' | False' | Return | Yield | Break | Next | Redo | Retry | IfModifier | UnlessModifier | WhileModifier | UntilModifier | RescueModifier | While | Until | For | Do | Case | When | Pattern | If | Unless | Elsif | Else | Begin | Ensure | Rescue | Exceptions | ExceptionVariable | ElementReference | ScopeResolution | Call | MethodCall | ArgumentList | ArgumentListWithParens | SplatArgument | HashSplatArgument | BlockArgument | Class | Constant deriving (Enum, Eq, Ord, Show) -- | 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 declaration) - where declaration = comment + where declaration = comment <|> class' + class' = rule Class (wrapU <$> (Declaration.Class <$> constant <*> pure [] <*> declaration)) + constant = rule Constant (wrapU <$> (Syntax.Identifier <$> content)) comment :: Assignment Grammar (Program Syntax a) comment = wrapU . Comment.Comment <$> (rule Comment content)