mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Pull the Ruby rules out to the top level.
This commit is contained in:
parent
1df2c979ec
commit
cec63c69aa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user