Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[:README] Ref | Explanation for Ragel variables #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ A multi-line FSM spec starts with %%{ and ends with }%%. A single-line FSM spec
( ’foo’ | ’bar’ )
0 @{ res = 1; };
}%%

%% write data;

int main( int argc, char **argv )
{
int cs, res = 0;
Expand All @@ -31,7 +31,7 @@ A multi-line FSM spec starts with %%{ and ends with }%%. A single-line FSM spec
printf("result = %i\n", res );
return 0;
}

#### Machine Definition

<name> = <expression>;
Expand Down Expand Up @@ -85,15 +85,15 @@ The union operation produces a machine that matches any string in machine one or
`expr & expr`

Intersection produces a machine that matches any string that is in both machine one and machine two

###### Difference

`expr - expr`

The difference operation produces a machine that matches strings that are in machine one but are not in machine two

For example: `(any - space)*`

###### Strong Difference

`expr -- expr`
Expand Down Expand Up @@ -144,7 +144,7 @@ Character-Level Negation is equivalent to (any - expr)
1. main := ( lower* >{ printf("action lower"); }) . ' ';
2. action A { printf("action lower"); }
main := ( lower* >A) . ' ';

#### Transition actions

* `expr > action` Entering Action
Expand Down Expand Up @@ -233,6 +233,50 @@ fcall *<expr>; | Push the current state and jump to the entry point given by <e
fret; | Return to the target state of the transition on which the last fcall was made.
fbreak; | fbreak; – Advance p, save the target state to cs and immediately break out of the execute loop. After an fbreak statement the p variable will point to the next character in the input. The current state will be the target of the current transition. Note that fbreak causes the target state’s to-state actions to be skipped.

#### Required state variables

The following piece of Rust code is an example for viable approach to
implementing a Ragel machine. This section provides an explanation for
variables used in this code.

```Rust
%%{
machine sync;
write data;
}%%

fn sync(data: &[u8]) {
let mut cs: i32 = 0; // Current state
let mut p = 0usize; // Current position
let mut pe = data.len(); // End position
let eof = 23;

%%{
action x {
println!("x");
}

action z {
println!("z")
}

action y {
println!("y")
}

main := 0x56 @z @!x (lower @y @!x)+ '\n';

write init;
write exec;
}%%
}
```

Variable name | Rust type | C/C+ type | Entailed by | Explanation
--- | --- | --- | --- | ---
`cs` | `i32` | `int` | - | Current state.
`p` | `usize` | `char *` | - | Current position.
`pe` | `usize` | `char *` | - | End position.

## Controlling Nondeterminism

Expand Down