Skip to content

Commit

Permalink
tutorial: make it work with the default lexer (parse integers)
Browse files Browse the repository at this point in the history
Closes: #231

Signed-off-by: Marco Molteni <marco.molteni@mailbox.org>
  • Loading branch information
marco-m authored and alecthomas committed Jun 12, 2022
1 parent 2246ffc commit fcdcf73
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions TUTORIAL.md
Expand Up @@ -58,7 +58,7 @@ working towards. Read on below for details.

type Value struct {
String *string ` @String`
Number *float64 `| @Float`
Number *float64 `| (@Float | @Int)`
}
```

Expand Down Expand Up @@ -147,6 +147,16 @@ type Value struct {
}
```

Since we want to parse also integers and the default lexer makes a difference,
we need to be explicit:

```go
type Value struct {
String *string ` @String`
Number *float64 `| (@Float | @Int)`
}
```

> Note: the grammar can cross fields.
Next, we'll match values and capture them into the `Property`. To recursively
Expand Down Expand Up @@ -189,7 +199,7 @@ type Property struct {

type Value struct {
String *string ` @String`
Number *float64 `| @Float`
Number *float64 `| (@Float | @Int)`
}
```

Expand Down Expand Up @@ -229,7 +239,7 @@ If a grammar node includes a field with the name `Pos` and type `lexer.Position`
type Value struct {
Pos lexer.Position
String *string ` @String`
Number *float64 `| @Float`
Number *float64 `| (@Float | @Int)`
}
```

Expand Down

0 comments on commit fcdcf73

Please sign in to comment.