Copyright | (c) 2020 Kowainik |
---|---|
License | MPL-2.0 |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Patterns for AST and syntax tree nodes search.
Synopsis
- data PatternAst
- = PatternAstConstant !Literal
- | PatternAstName !NameMeta !PatternType
- | PatternAstVarName !String
- | PatternAstNode !(Set (FastString, FastString))
- | PatternAstNodeExact !(Set (FastString, FastString)) ![PatternAst]
- | PatternAstAnything
- | PatternAstOr !PatternAst !PatternAst
- | PatternAstAnd !PatternAst !PatternAst
- | PatternAstNeg !PatternAst
- | PatternAstIdentifierDetailsDecl !DeclType
- data Literal
- namesToPatternAst :: NonEmpty (NameMeta, PatternType) -> PatternAst
- anyNamesToPatternAst :: NonEmpty NameMeta -> PatternAst
- app :: PatternAst -> PatternAst -> PatternAst
- opApp :: PatternAst -> PatternAst -> PatternAst -> PatternAst
- constructor :: PatternAst
- constructorNameIdentifier :: PatternAst
- dataDecl :: PatternAst
- fixity :: PatternAst
- fun :: PatternAst
- guardBranch :: PatternAst
- lazyField :: PatternAst
- range :: PatternAst -> PatternAst -> PatternAst
- rhs :: PatternAst
- tuple :: PatternAst
- typeSig :: PatternAst
- case' :: PatternAst
- lambdaCase :: PatternAst
- patternMatchBranch :: PatternAst
- patternMatchArrow :: PatternAst -> PatternAst
- patternMatch_ :: PatternAst -> PatternAst
- literalPat :: PatternAst
- wildPat :: PatternAst
- literalAnns :: (FastString, FastString)
Type
data PatternAst Source #
Query pattern used to search AST nodes in HIE AST. This data type tries to mirror HIE AST to each future matching, so it's quite low-level, but helper functions are provided.
PatternAstConstant !Literal | Integer constant in code. |
PatternAstName !NameMeta !PatternType | Name of a specific function, variable or data type. |
PatternAstVarName !String | Variable name. |
PatternAstNode !(Set (FastString, FastString)) | Set of context info (pairs of tags) | AST node with tags for current node and children patterns. This pattern should match the node exactly. |
PatternAstNodeExact | |
| |
PatternAstAnything | |
PatternAstOr !PatternAst !PatternAst | Choice between patterns. Should match either of them. |
PatternAstAnd !PatternAst !PatternAst | Union of patterns. Should match both of them. |
PatternAstNeg !PatternAst | Negation of pattern. Should match everything except this pattern. |
PatternAstIdentifierDetailsDecl !DeclType | AST node with the specified Identifier details (only |
Instances
Eq PatternAst Source # | |
Defined in Stan.Pattern.Ast (==) :: PatternAst -> PatternAst -> Bool # (/=) :: PatternAst -> PatternAst -> Bool # | |
Show PatternAst Source # | |
Defined in Stan.Pattern.Ast showsPrec :: Int -> PatternAst -> ShowS # show :: PatternAst -> String # showList :: [PatternAst] -> ShowS # | |
PatternBool PatternAst Source # | |
Defined in Stan.Pattern.Ast (?) :: PatternAst Source # neg :: PatternAst -> PatternAst Source # (|||) :: PatternAst -> PatternAst -> PatternAst Source # (&&&) :: PatternAst -> PatternAst -> PatternAst Source # |
Helpers
namesToPatternAst :: NonEmpty (NameMeta, PatternType) -> PatternAst Source #
Function that creates PatternAst
from the given non-empty list of pairs
NameMeta
and PatternType
.
If the list contains only one PatternType
then it is simple PatternAstName
.
Else it is PatternAstOr
of all such PatternAstName
s.
anyNamesToPatternAst :: NonEmpty NameMeta -> PatternAst Source #
Like namesToPatternAst
but doesn't care about types.
eDSL
app :: PatternAst -> PatternAst -> PatternAst Source #
app f x
is a pattern for function application f x
.
opApp :: PatternAst -> PatternAst -> PatternAst -> PatternAst Source #
opApp x op y
is a pattern for operator application x
.op
y
constructor :: PatternAst Source #
Constructor of a plain data type or newtype. Children of node that matches this pattern are constructor fields.
constructorNameIdentifier :: PatternAst Source #
Constructor name Identifier info
dataDecl :: PatternAst Source #
data
or newtype
declaration.
fixity :: PatternAst Source #
Pattern for the top-level fixity declaration:
infixr 7 ***, +++, ???
fun :: PatternAst Source #
Pattern for the function definition:
foo x y = ...
guardBranch :: PatternAst Source #
Pattern for a single guard
branch:
| x < y = ...
lazyField :: PatternAst Source #
Lazy data type field. Comes in two shapes:
- Record field, like:
foo :: Text
- Simple type:
Int
range :: PatternAst -> PatternAst -> PatternAst Source #
range a b
is a pattern for [a .. b]
rhs :: PatternAst Source #
Pattern for the right-hand-side. Usually an equality sign.
foo = baz
tuple :: PatternAst Source #
Pattern for tuples:
- Type signatures: foo :: (Int, Int, Int, Int)
- Literals: (True, 0, [], Nothing)
typeSig :: PatternAst Source #
Pattern for the function type signature declaration:
foo :: Some -> Type
Pattern matching
case' :: PatternAst Source #
case'
is a pattern for case EXP of
expression (not considering branches).
lambdaCase :: PatternAst Source #
lambdaCase
is a pattern for case
expression (not considering branches).
patternMatchBranch :: PatternAst Source #
Pattern to represent one pattern matching branch.
patternMatchArrow :: PatternAst -> PatternAst Source #
Pattern to represent right side of the pattern matching, e.g. -> "foo"
.
patternMatch_ :: PatternAst -> PatternAst Source #
Pattern to represent one pattern matching branch on _
.
literalPat :: PatternAst Source #
Pattern for literals in pattern matching.
Note: presents on GHC >=8.10 only.
wildPat :: PatternAst Source #
Pattern for _
in pattern matching.
Note: presents on GHC >=8.10 only.
More low-level interface
literalAnns :: (FastString, FastString) Source #
Annotations for constants: 0, "foo", etc.