-
Notifications
You must be signed in to change notification settings - Fork 0
Query Examples
Regular expressions are tricky to get right, so whatever you are searching for, get ready for both false positives and false negatives. With that in mind, here are some interesting queries:
Matches lines such as:
type Sigma :: forall s -> (s ~> Type) -> Type
Here's how it works:
- The
^
matches the start of a line (rules out some false positives) - The word
type
is a keyword that begins a standalone kind signature -
\s
matches a single whitespace character, and\s+
matches one or more -
\w+
matches a one or more word characters, i.e. an alphanumeric identifier -
::
matches the double colon syntax of type signatures
Matches lines such as:
data HList :: [*] -> * where
Here's how it works:
-
::
matches the double colon syntax of type signatures -
\[
and\]
match the square brackets (list syntax) -
\*
matches the star symbol used to denote the type of types
Matches lines such as:
Map f (x ': xs) = (Apply f x) ': xs
Side note: this quotation mark is the DataKinds
syntax for namespace disambiguation, and it's always redundant in case of :
. And yet people like to write it anyway, as evidenced by the results of this query!
^(forall|qualified|as|family|role) =
Matches lines such as:
forall = token (Internal.forall Internal.Unicode)
Here's how it works:
- The
(
and)
are not escaped, so they are part of regex syntax - The
|
stands for logical ‘or’.
Matches lines such as:
TM.adjust (+1) someKey mapRef
Here's how it works:
-
\(
and\)
are escaped, so they match the parentheses -
\+
is escaped, to it matches the+
symbol -
\d+
matches a sequence of one or more digits
Side note: while (-1)
is a negative number, (+1)
is an operator section. It would be more clear to write it as (+ 1)
to avoid confusion, but this query reveals that there's plenty of code that doesn't use that extra space.