mirror of
https://github.com/github/semantic.git
synced 2025-01-03 21:16:12 +03:00
Move Syntax into the Program type synonym.
This commit is contained in:
parent
88c4081e0d
commit
731c7a5c1d
@ -28,7 +28,7 @@ type Syntax = Union
|
||||
|
||||
|
||||
-- | A program in some syntax functor, over which we can perform analyses.
|
||||
type Program = Freer
|
||||
type Program = Freer Syntax
|
||||
|
||||
|
||||
-- | Statically-known rules corresponding to symbols in the grammar.
|
||||
@ -36,36 +36,36 @@ mkSymbolDatatype (mkName "Grammar") tree_sitter_ruby
|
||||
|
||||
|
||||
-- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax.
|
||||
assignment :: Assignment Grammar [Program Syntax (Maybe a)]
|
||||
assignment :: Assignment Grammar [Program (Maybe a)]
|
||||
assignment = rule Program *> children (many declaration)
|
||||
|
||||
declaration :: Assignment Grammar (Program Syntax (Maybe a))
|
||||
declaration :: Assignment Grammar (Program (Maybe a))
|
||||
declaration = comment <|> class' <|> method
|
||||
|
||||
class' :: Assignment Grammar (Program Syntax (Maybe a))
|
||||
class' :: Assignment Grammar (Program (Maybe a))
|
||||
class' = wrapU <$ rule Class
|
||||
<*> children (Declaration.Class <$> constant <*> pure [] <*> many declaration)
|
||||
|
||||
constant :: Assignment Grammar (Program Syntax a)
|
||||
constant :: Assignment Grammar (Program a)
|
||||
constant = wrapU . Syntax.Identifier <$ rule Constant <*> content
|
||||
|
||||
identifier :: Assignment Grammar (Program Syntax a)
|
||||
identifier :: Assignment Grammar (Program a)
|
||||
identifier = wrapU . Syntax.Identifier <$ rule Identifier <*> content
|
||||
|
||||
method :: Assignment Grammar (Program Syntax (Maybe a))
|
||||
method :: Assignment Grammar (Program (Maybe a))
|
||||
method = wrapU <$ rule Method
|
||||
<*> children (Declaration.Method <$> identifier <*> pure [] <*> pure (return Nothing))
|
||||
|
||||
statement :: Assignment Grammar (Program Syntax a)
|
||||
statement :: Assignment Grammar (Program a)
|
||||
statement = wrapU <$ rule Return <*> children (Statement.Return <$> expr)
|
||||
<|> wrapU <$ rule Yield <*> children (Statement.Yield <$> expr)
|
||||
<|> expr
|
||||
|
||||
comment :: Assignment Grammar (Program Syntax a)
|
||||
comment :: Assignment Grammar (Program a)
|
||||
comment = wrapU . Comment.Comment <$ rule Comment <*> content
|
||||
|
||||
if' :: Assignment Grammar (Program Syntax a)
|
||||
if' :: Assignment Grammar (Program a)
|
||||
if' = wrapU <$ rule If <*> children (Statement.If <$> expr <*> expr <*> expr)
|
||||
|
||||
expr :: Assignment Grammar (Program Syntax a)
|
||||
expr :: Assignment Grammar (Program a)
|
||||
expr = if'
|
||||
|
Loading…
Reference in New Issue
Block a user