| Copyright | (c) 2020 Kowainik |
|---|---|
| License | MPL-2.0 |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Stan.Pattern.Ast
Description
Patterns for AST and syntax tree nodes search.
Synopsis
- data PatternAst
- = PatternAstConstant !Literal
- | PatternAstName !NameMeta !PatternType
- | PatternAstVarName !String
- | PatternAstNode !(Set NodeAnnotation)
- | PatternAstNodeExact !(Set NodeAnnotation) ![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 :: NodeAnnotation
Type
data PatternAst #
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.
Constructors
| PatternAstConstant !Literal | Integer constant in code. |
| PatternAstName !NameMeta !PatternType | Name of a specific function, variable or data type. |
| PatternAstVarName !String | Variable name. |
| PatternAstNode | AST node with tags for current node and any children. |
Fields
| |
| PatternAstNodeExact | |
Fields
| |
| 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
| Show PatternAst # | |
Defined in Stan.Pattern.Ast Methods showsPrec :: Int -> PatternAst -> ShowS # show :: PatternAst -> String # showList :: [PatternAst] -> ShowS # | |
| Eq PatternAst # | |
Defined in Stan.Pattern.Ast | |
| PatternBool PatternAst # | |
Defined in Stan.Pattern.Ast Methods (?) :: PatternAst # neg :: PatternAst -> PatternAst # (|||) :: PatternAst -> PatternAst -> PatternAst # (&&&) :: PatternAst -> PatternAst -> PatternAst # | |
Constructors
| ExactNum !Int | |
| ExactStr !ByteString | |
| PrefixStr !ByteString | |
| ContainStr !ByteString | |
| AnyLiteral |
Helpers
namesToPatternAst :: NonEmpty (NameMeta, PatternType) -> PatternAst #
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 PatternAstNames.
anyNamesToPatternAst :: NonEmpty NameMeta -> PatternAst #
Like namesToPatternAst but doesn't care about types.
eDSL
app :: PatternAst -> PatternAst -> PatternAst #
app f x is a pattern for function application f x.
opApp :: PatternAst -> PatternAst -> PatternAst -> PatternAst #
opApp x op y is a pattern for operator application x .op y
Constructor of a plain data type or newtype. Children of node that matches this pattern are constructor fields.
constructorNameIdentifier :: PatternAst #
Constructor name Identifier info
dataDecl :: PatternAst #
data or newtype declaration.
fixity :: PatternAst #
Pattern for the top-level fixity declaration:
infixr 7 ***, +++, ???
fun :: PatternAst #
Pattern for the function definition:
foo x y = ...
Pattern for a single guard branch:
| x < y = ...
lazyField :: PatternAst #
Lazy data type field. Comes in two shapes:
- Record field, like:
foo :: Text - Simple type:
Int
range :: PatternAst -> PatternAst -> PatternAst #
range a b is a pattern for [a .. b]
rhs :: PatternAst #
Pattern for the right-hand-side. Usually an equality sign.
foo = baz
tuple :: PatternAst #
Pattern for tuples:
- Type signatures: foo :: (Int, Int, Int, Int)
- Literals: (True, 0, [], Nothing)
typeSig :: PatternAst #
Pattern for the function type signature declaration:
foo :: Some -> Type
Pattern matching
case' :: PatternAst #
case' is a pattern for case EXP of expression (not considering branches).
lambdaCase is a pattern for case expression (not considering branches).
patternMatchBranch :: PatternAst #
Pattern to represent one pattern matching branch.
patternMatchArrow :: PatternAst -> PatternAst #
Pattern to represent right side of the pattern matching, e.g. -> "foo".
patternMatch_ :: PatternAst -> PatternAst #
Pattern to represent one pattern matching branch on _.
Pattern for literals in pattern matching.
Note: presents on GHC >=8.10 only.
wildPat :: PatternAst #
Pattern for _ in pattern matching.
Note: presents on GHC >=8.10 only.
More low-level interface
literalAnns :: NodeAnnotation #
Annotations for constants: 0, "foo", etc.