7 #include <hilti/ast/builder/expression.h> 8 #include <hilti/ast/operator.h> 9 #include <hilti/ast/operators/common.h> 10 #include <hilti/ast/types/bytes.h> 11 #include <hilti/ast/types/computed.h> 12 #include <hilti/ast/types/integer.h> 13 #include <hilti/ast/types/stream.h> 15 #include <spicy/ast/types/unit.h> 19 BEGIN_METHOD(unit, Offset)
20 auto signature()
const {
26 Returns the offset of the current location in the input stream relative to the 27 unit's start. If executed from inside a field hook, the offset will represent 28 the first byte that the field has been parsed from. If this method is called 29 before the unit's parsing has begun, it will throw a runtime exception. Once 30 parsing has started, the offset will remain available for the unit's entire 33 Usage of this method requires the unit to be declared with the ``%random-access`` 39 BEGIN_METHOD(unit, Position) 40 auto signature()
const {
46 Returns an iterator to the current position in the unit's input stream. If 47 executed from inside a field hook, the position will represent the first byte 48 that the field has been parsed from. If this method is called before the unit's 49 parsing has begun, it will throw a runtime exception. 51 Usage of this method requires the unit to be declared with the ``%random-access`` 58 BEGIN_METHOD(unit, Input) 59 auto signature()
const {
65 Returns an iterator referring to the input location where the current unit has 66 begun parsing. If this method is called before the units parsing has begun, it 67 will throw a runtime exception. Once available, the input position will remain 68 accessible for the unit's entire life time. 70 Usage of this method requires the unit to be declared with the ``%random-access`` 76 BEGIN_METHOD(unit, SetInput) 77 auto signature()
const {
84 Moves the current parsing position to *i*. The iterator *i* must be into the 85 input of the current unit, or the method will throw a runtime execption. 87 Usage of this method requires the unit to be declared with the ``%random-access`` 93 BEGIN_METHOD(unit, Find) 94 auto signature()
const {
110 Searches a *needle* pattern inside the input region defined by where the unit 111 began parsing and its current parsing position. If executed from inside a field 112 hook, the current parasing position will represent the *first* byte that the 113 field has been parsed from. By default, the search will start at the beginning 114 of that region and scan forward. If the direction is 115 ``spicy::Direcction::Backward``, the search will start at the end of the region 116 and scan backward. In either case, a starting position can also be explicitly 117 given, but must lie inside the same region. 119 Usage of this method requires the unit to be declared with the ``%random-access`` 125 BEGIN_METHOD(unit, ConnectFilter) 126 auto signature()
const {
129 .id =
"connect_filter",
130 .args = {{.id =
"filter",
134 Connects a separate filter unit to transform the unit's input transparently 135 before parsing. The filter unit will see the original input, and this unit will 136 receive everything the filter passes on through ``forward()``. 138 Filters can be connected only before a unit's parsing begins. The latest 139 possible point is from inside the target unit's ``%init`` hook. 144 BEGIN_METHOD(unit, Forward) 145 auto signature()
const {
151 If the unit is connected as a filter to another one, this method forwards 152 transformed input over to that other one to parse. If the unit is not connected, 153 this method will silently discard the data. 158 BEGIN_METHOD(unit, ForwardEod) 159 auto signature()
const {
165 If the unit is connected as a filter to another one, this method signals that 166 other one that end of its input has been reached. If the unit is not connected, 167 this method will not do anything. 172 BEGIN_METHOD(unit, Backtrack) 173 auto signature()
const {
179 Aborts parsing at the current position and returns back to the most recent 180 ``&try`` attribute. Turns into a parse error if there's no ``&try`` in scope. 185 static inline auto contextResult(
bool is_const) {
186 return [=](
const std::vector<Expression>& ,
187 const std::vector<Expression>& resolved_ops) -> std::optional<Type> {
188 if ( resolved_ops.empty() )
189 return type::DocOnly(
"<context>&");
191 return type::Computed(hilti::builder::member(hilti::builder::id(
"self"),
"__context"));
195 BEGIN_METHOD(unit, ContextConst)
196 auto signature()
const {
198 .result = contextResult(
true),
202 Returns a reference to the ``%context`` instance associated with the unit. 207 BEGIN_METHOD(unit, ContextNonConst) 208 auto signature()
const {
210 .result = contextResult(
false),
214 Returns a reference to the ``%context`` instance associated with the unit.
Definition: optional.h:13
Definition: reference.h:16
Type self
Definition: operator.h:225
Definition: bitfield.h:18
Definition: operator.h:224