Skip to content

Commit b70f00a

Browse files
committed
Allow the guide to consume the eos_token
1 parent af7426f commit b70f00a

File tree

4 files changed

+3
-10
lines changed

4 files changed

+3
-10
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ next_allowed_tokens = guide.advance(allowed_tokens[-1])
136136
# To check if Guide is finished:
137137
guide.is_finished()
138138

139-
# If it's finished then this assertion holds:
140-
assert guide.get_tokens() == [vocabulary.get_eos_token_id()]
141-
```
142-
143139
## How to contribute?
144140

145141
### Setup

src/index.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ impl Index {
226226

227227
/// Returns transition state for a given state and token id or `None` otherwise.
228228
pub fn next_state(&self, state: &StateId, token_id: &TokenId) -> Option<StateId> {
229-
if token_id == &self.eos_token_id {
230-
return None;
231-
}
232229
Some(*self.transitions.get(state)?.get(token_id)?)
233230
}
234231

@@ -284,7 +281,7 @@ mod tests {
284281
assert_eq!(index.next_state(&initial_state, token_id), Some(state));
285282
assert!(index.is_final_state(&state));
286283

287-
assert_eq!(index.next_state(&state, &eos_token_id), None);
284+
assert_eq!(index.next_state(&state, &eos_token_id), Some(state));
288285
assert_eq!(index.next_state(&state, token_id), None);
289286
}
290287

src/json_schema/parsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a> Parser<'a> {
6565

6666
fn parse_empty_object(&mut self) -> Result<String> {
6767
// JSON Schema Spec: Empty object means unconstrained, any json type is legal
68-
let types = vec![
68+
let types = [
6969
json!({"type": "boolean"}),
7070
json!({"type": "null"}),
7171
json!({"type": "number"}),

tests/test_guide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_rollback_interface(index):
210210
([1], True), # single allowed token: accept
211211
([2], True), # different allowed token: accept
212212
([1, 1], False), # too long for r"[1-9]": reject
213-
([2, 3], False), # extra token: reject
213+
([2, 3], True), # extra token: accept at the final state
214214
],
215215
)
216216
def test_accepts_tokens_correctness(index, seq, expected):

0 commit comments

Comments
 (0)