74 | | }}} |
75 | | = Expression entity = |
76 | | |
77 | | Expressions are the basic syntactic elements of Erlang, and they are represented by expression entities. This is the only syntactic entity in the query language, it is mainly useful to express relations that cannot be calculated by selectors of other entities. Patterns and guards are also represented as expressions, however, there are syntactic units which are not expressions and cannot be handled in this query language, like clauses and module attributes. |
78 | | |
79 | | == Initial selector == |
80 | | * {{{@expr}}} a query can be started from the currently selected expression using this selector. |
81 | | |
82 | | == Selectors == |
83 | | |
84 | | The following selectors work on expression entities. |
85 | | |
86 | | Note that an expression is always treated as a single unit with its subexpressions, even in case expressions with more clauses, like {{{if}}} or {{{case}}}. |
87 | | |
88 | | ''In parentheses you find the type of the result elements.'' |
89 | | |
90 | | * {{{fundef}}} (''function''): returns the function entity which contains the expression. |
91 | | * {{{funs}}} (''function''): returns every function entity referred directly in the expression. |
92 | | * {{{vars}}} (''variable''): returns every variable entity referred in the expression. |
93 | | * {{{records}}} (''record''): returns every record entity referred in the expression. |
94 | | * {{{macros}}} (''macro''): returns every macro entity referred in the expression. |
95 | | * {{{sub}}} (''expression''): returns the set of expressions that are nested in the expression in any depth. This is mainly useful together with the {{{type}}} property. |
96 | | * {{{top}}} (''expression''): returns the expression's top-level expression. |
97 | | * {{{file}}} (''file''): returns the file entity where the expression is located. |
98 | | * {{{origin}}} (''expression''): returns the origin of the expression's value determined by data-flow analysis. |
99 | | * {{{reach}}} (''expression''): returns the places where the expression's value is copied, determined by data-flow analysis. |
100 | | |
101 | | == Properties == |
102 | | |
103 | | These properties are defined for expression entities. |
104 | | |
105 | | Note that some of them depends on the context of the expression, which makes possible selecting tail calls or indexing function arguments. |
106 | | |
107 | | * {{{type}}} (''atom''): returns the type of the expression. The type can |
108 | | be one of the following: |
109 | | * {{{application}}}: {{{func(Arg1, ...)}}} |
110 | | * {{{implicit_fun}}}: {{{fun func/1}}} |
111 | | * {{{parenthesis}}}: {{{(Expr)}}} |
112 | | * {{{tuple}}}: {{{\{A, B, C\}}} |
113 | | * {{{binary}}}: {{{<<3.14/float>>}}} |
114 | | * {{{binary_field}}}: {{{3.14/float}}} in the previous binary |
115 | | * {{{record_access}}}: {{{Rec#name.fld}}} |
116 | | * {{{record_expr}}}: {{{#name{fld=Val} }}} |
117 | | * {{{record_update}}}: {{{Rec#name{fld=Val} }}} |
118 | | * {{{record_index}}}: {{{#name.fld}}} |
119 | | * {{{match_expr}}}: {{{Pattern = Expr}}} |
120 | | * {{{send_expr}}}: {{{Pid ! Expr}}} |
121 | | * {{{'bnot'}}}: {{{bnot Expr}}} (there are other prefix operators like this) |
122 | | * {{{'+'}}}: {{{A + B}}} (there are other infix operators like this) |
123 | | * {{{cons}}}: {{{[1, 2, 3 | Tail]}}} |
124 | | * {{{list}}}: {{{1, 2, 3}}} in the previous list |
125 | | * {{{nil}}}: {{{[]}}} |
126 | | * {{{atom}}}, {{{char}}}, {{{float}}}, {{{integer}}}, {{{string}}}: constants |
127 | | * {{{variable}}}: {{{Var}}} |
128 | | * {{{catch_expr}}}: {{{catch Expr}}} |
129 | | * {{{list_comp}}}: {{{[A || A <- L, A > 0]}}} |
130 | | * {{{list_gen}}}: {{{A <- L}}} in the previous list comprehension |
131 | | * {{{filter}}}: {{{A > 0}}} in the previous list comprehension |
132 | | * {{{bin_comp}}}: {{{ {<< <<C/utf8>> || <<C:16>> <= Str >>} }}} |
133 | | * {{{binary_gen}}}: {{{<<C:16>> <= Str}}} in the previous binary comprehension |
134 | | * {{{block_expr}}}: {{{begin ... end}}} |
135 | | * {{{if_expr}}}: {{{if ... end}}} |
136 | | * {{{fun_expr}}}: {{{fun () -> ... end}}} |
137 | | * {{{receive_expr}}}: {{{receive ... end}}} |
138 | | * {{{case_expr}}}: {{{case Expr of ... end}}} |
139 | | * {{{try_expr}}}: {{{try ... end}}} |
140 | | |
141 | | * {{{value}}}: returns the value of the expression. It is either the value of a constant expression or an operator of an operator-based expression. |
142 | | * {{{class}}} (''atom''): returns the class of the expression: it can be either {{{expr}}} (stands for single expressions), {{{pattern}}}, or {{{guard}}}. |
143 | | * {{{last}}} (''bool''): returns true if the expression is the last expression of the clause. |
144 | | * {{{index}}} (''int''): returns the index of the expression in the containing expression list. |
145 | | * {{{tailcall}}} (''bool''): returns true if the expression is a tail call. Tail call expressions are function applications, which are the last expressions of their containing clause. |