View Source Sourceror.Identifier (Sourceror v1.7.0)
Functions to identify an classify forms and quoted expressions.
Summary
Functions
Checks if the given quoted form is an atomic literal in the AST.
Checks if the given identifier is a binary op.
Checks if the given quoted form is a call.
Checks if the given quoted form is an identifier, such as a variable.
Checks if the given identifier is a pipeline operator.
Checks if the given quoted form is a qualified call.
Checks if the given quoted form is a reserved block name.
Checks if the given identifier is an unary op.
Checks if the given quoted form is an unqualified call.
Checks if the given atom is a valid module alias.
Functions
Checks if the given quoted form is an atomic literal in the AST.
This set includes numbers, atoms, and strings, but not collections like tuples, lists, or maps.
This guard returns true
for literals that are the only elements inside
of a :__block__
, such as {:__block__, [], [:literal]}
.
Examples
iex> is_atomic_literal(1)
true
iex> is_atomic_literal(1.0)
true
iex> is_atomic_literal(:foo)
true
iex> is_atomic_literal("foo")
true
iex> is_atomic_literal({:__block__, [], [1]})
true
iex> is_atomic_literal({:__block__, [], [1, 2]})
false
iex> is_atomic_literal({:__block__, [], [{:node, [], nil}]})
false
iex> is_atomic_literal('foo')
false
Checks if the given identifier is a binary op.
Examples
iex> is_binary_op(:+)
true
Checks if the given quoted form is a call.
Calls are any form of the shape {form, metadata, args}
where args is
a list, with the exception of blocks and aliases, which are identified
by the forms :__block__
and :__aliases__
.
Examples
iex> "node()" |> Sourceror.parse_string!() |> is_call()
true
iex> "Kernel.node()" |> Sourceror.parse_string!() |> is_call()
true
iex> "%{}" |> Sourceror.parse_string!() |> is_call()
true
iex> "@attr" |> Sourceror.parse_string!() |> is_call()
true
iex> "node" |> Sourceror.parse_string!() |> is_call()
false
iex> "1" |> Sourceror.parse_string!() |> is_call()
false
iex> "(1; 2)" |> Sourceror.parse_string!() |> is_call()
false
iex> "Macro.Env" |> Sourceror.parse_string!() |> is_call()
false
Checks if the given quoted form is an identifier, such as a variable.
Examples
iex> "node" |> Sourceror.parse_string!() |> is_identifier()
true
iex> "node()" |> Sourceror.parse_string!() |> is_identifier()
false
iex> "1" |> Sourceror.parse_string!() |> is_identifier()
false
Checks if the given identifier is a pipeline operator.
Examples
iex> is_pipeline_op(:|>)
true
Checks if the given quoted form is a qualified call.
All unqualified calls would also return true
if passed to is_call/1
,
but they have the shape {{:., dot_metadata, dot_args}, metadata, args}
.
Examples
iex> "Kernel.node()" |> Sourceror.parse_string!() |> is_qualified_call()
true
iex> "__MODULE__.node()" |> Sourceror.parse_string!() |> is_qualified_call()
true
iex> "foo.()" |> Sourceror.parse_string!() |> is_qualified_call()
true
iex> "foo.bar()" |> Sourceror.parse_string!() |> is_qualified_call()
true
iex> "node()" |> Sourceror.parse_string!() |> is_qualified_call()
false
iex> "%{}" |> Sourceror.parse_string!() |> is_qualified_call()
false
iex> "@attr" |> Sourceror.parse_string!() |> is_qualified_call()
false
iex> "1" |> Sourceror.parse_string!() |> is_qualified_call()
false
iex> "(1; 2)" |> Sourceror.parse_string!() |> is_qualified_call()
false
iex> "Macro.Env" |> Sourceror.parse_string!() |> is_qualified_call()
false
Checks if the given quoted form is a reserved block name.
Examples
iex> is_reserved_block_name(:do)
true
iex> is_reserved_block_name(:else)
true
iex> is_reserved_block_name(:catch)
true
iex> is_reserved_block_name(:after)
true
iex> is_reserved_block_name(:rescue)
true
iex> is_reserved_block_name(:foo)
false
Checks if the given identifier is an unary op.
Examples
iex> is_unary_op(:+)
true
Checks if the given quoted form is an unqualified call.
All unqualified calls would also return true
if passed to is_call/1
,
but they have the shape {atom, metadata, args}
.
Examples
iex> "node()" |> Sourceror.parse_string!() |> is_unqualified_call()
true
iex> "%{}" |> Sourceror.parse_string!() |> is_unqualified_call()
true
iex> "@attr" |> Sourceror.parse_string!() |> is_unqualified_call()
true
iex> "node" |> Sourceror.parse_string!() |> is_unqualified_call()
false
iex> "1" |> Sourceror.parse_string!() |> is_unqualified_call()
false
iex> "(1; 2)" |> Sourceror.parse_string!() |> is_unqualified_call()
false
iex> "Macro.Env" |> Sourceror.parse_string!() |> is_unqualified_call()
false
Checks if the given atom is a valid module alias.
Examples
iex> valid_alias?(Foo)
true
iex> valid_alias?(:foo)
false