You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Docs/FexElementsRef.md
+41-3Lines changed: 41 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,20 +8,24 @@ Flow Expressions are defined by a structure of *FexElements* built via a Fluent
8
8
## Factory: `FlowExpression<T>`
9
9
10
10
The `FlowExpression<T>` class operates as a *factory* to build and return FexElements which are used in other productions or as the *Axiom* (root) to be run.
11
-
> The innards of each element are built via the encapsulated `FexBuilder<T>` class.
11
+
> - The innards of each element are built via the encapsulated `FexBuilder<T>` class.
12
+
> -**`Skip()` feature:** Sometimes when parsing spaces/white-space/other needs to be skipped between tokens:
13
+
> - FexBuilder provides a common Skip() action that can be placed anywhere for this purpose.
14
+
> - FlowExpression has a method `DefSkip(Action<Ctx> skipAction)` to define what this skip action must be and must be defined before creating any elements.
12
15
13
16
**Basic mechanism:**
14
17
```csharp
15
18
usingPsw.FlowExpressions;
16
19
17
20
// Create a FlowEpression factory using FexScanner as the context:
18
21
varfex=newFlowExpression<FexScanner>();
22
+
fex.DefSkip(Action<T>skipAction) // Optionally define the Skip action.
19
23
20
-
// Create a sequence element (element is of type FexElement<T>):
24
+
// Create a sequence element (returned element is of type FexElement<T>):
|[`OneOf(o => o...)*`](#id-oneof)|**One Of:** Set of sequences that are *Or'd* together and one of them must succeed to pass. |
@@ -189,6 +194,39 @@ See the Expression example which uses a GlobalPreOp to skip all spaces before th
189
194
190
195
[`TOC`](#id-toc)
191
196
197
+
---
198
+
<aid="id-skip"></a>
199
+
### Skip Actions:
200
+
201
+
Used when a common skipping action is required between tokens:
202
+
- Typically used to skip spaces, comments and newlines etc. between tokens when parsing scripts.
203
+
- The action to perform must be pre-defined via `FexExpression.DefSkip(Action<Ctx> skipAction)` and must be defined before any other productions.
204
+
- The Skip operation may be placed anywhere and runs as an action that does not affects the validity of a sequence. If no skip action is define it's just ignored.
205
+
206
+
<br/>
207
+
208
+
> **`GlobalSkip()`**
209
+
> - Sets the skip action as a GlobalPreOp.
210
+
211
+
```csharp
212
+
varfex=newFlowExpression<FexScanner>(); // Flow Expression using FexScanner.
213
+
fex.DefSkip(c=>c.SkipSp()); // Define a Skip operation to skip spaces.
214
+
stringdcode="", acode="", number=""; // Will record values in here.
215
+
216
+
// Build the flow expression with 'Axiom' tnumber:
0 commit comments