Skip to content

Commit

Permalink
Redefine severity (#119)
Browse files Browse the repository at this point in the history
See table in src/value/README.md for details.
  • Loading branch information
phorward authored Sep 26, 2023
1 parent 5130dd2 commit b776065
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/value/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ This is how Tokay builtin values are converted during binary operations.
| **str** | str | str | str | str | str | str | str | dict | list
| **dict** | dict | dict | dict | dict | dict | dict | dict | dict | list
| **list** | list | list | list | list | list | list | list | list | list

# Token severity

| Severity | Used by |
| -------- | ----------------------------------------------------------------------- |
| 0 | `_`, `__`, `Touch` |
| 5 | Any token (`Char`, `Match`, `Int`, `Float`, `Number`), parselet default |
| 10 | Any explicitly pushed value |
6 changes: 3 additions & 3 deletions src/value/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl List {
tokay_method!("list_iadd : @list, append", {
// Don't append void
if append.is_void() {
return Ok(list)
return Ok(list);
}

// In case list is not a list, make it a list.
Expand Down Expand Up @@ -199,7 +199,7 @@ impl List {
tokay_method!("list_add : @list, append", {
// Don't append void
if append.is_void() {
return Ok(list)
return Ok(list);
}

// In case list is not a list, make it a list.
Expand Down Expand Up @@ -227,7 +227,7 @@ impl List {
tokay_method!("list_push : @list, item, index=void", {
// Don't push void
if item.is_void() {
return Ok(list)
return Ok(list);
}

// In case list is not a list, make it a list.
Expand Down
2 changes: 1 addition & 1 deletion src/value/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Token {
range,
None,
if matches!(self, Token::Touch(_)) {
1
0
} else {
5
},
Expand Down
2 changes: 1 addition & 1 deletion src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl<'program, 'reader, 'thread, 'parselet> Context<'program, 'reader, 'thread,

let mut list = List::new(); // List collector
let mut dict = Dict::new(); // Dict collector
let mut max = 0; // Maximum severity
let mut max = self.parselet.severity; // Require at least parselet severity level
let mut idx = 0; // Keep the order for dicts

// Collect any significant captures and values
Expand Down
6 changes: 3 additions & 3 deletions tests/parselet_leftrec.tok
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# direct1
D1: @{
D1? ''a''
D1? Char<a>
}
'D1' print(D1)

# direct2
D2: @{
D2 'b'
'a'
D2 Char<b>
Char<a>
}
'D2' print(D2)

Expand Down
1 change: 0 additions & 1 deletion tests/token_modifiers.tok
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Int
#abcbcd ad
#Hello, World, Beta, Test
#---
#(("a", "b"), ("a", "b"), ("a", "b"))
#("b", "b", "b")
#("b", ("b", "b", "b"), "b")
#(("a", "b"), ("a", ("b", "b", "b")), ("b", "b"), ("a", "b"), "b")
Expand Down

0 comments on commit b776065

Please sign in to comment.