1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Pull the Ruby rules out to the top level.

This commit is contained in:
Rob Rix 2017-04-07 14:29:48 -04:00
parent 1df2c979ec
commit cec63c69aa

View File

@ -35,14 +35,26 @@ data Grammar = Program | Uninterpreted | BeginBlock | EndBlock | Undef | Alias |
-- | Assignment from AST in Rubys grammar onto a program in Rubys 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