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

Grammar.parse() misses one letter, when parsing as bits #318

Closed
alex9849 opened this issue Feb 10, 2025 · 3 comments
Closed

Grammar.parse() misses one letter, when parsing as bits #318

alex9849 opened this issue Feb 10, 2025 · 3 comments
Assignees
Labels
prio: medium Medium priority issue

Comments

@alex9849
Copy link
Collaborator

When parsing a byte stream (bytes) using the grammar.parse()-method, the last letter is missing.

Steps to reproduce:

<start> ::= <entry_bit>
<entry_bit> ::= <bit>+
<entry_byte> ::= <byte>+
<byte> ::= <bit>{8}
<bit> ::= 0 | 1

Run:

with open("bit_grammar.fan") as f:
    grammar, constraints = parse(f, use_stdlib=False)
grammar.parse(b'test', NonTerminal("<entry_bit>")).to_bytes() # returns b'tes'
grammar.parse(b'test', NonTerminal("<entry_byte>")).to_bytes() # returns b'test'
@alex9849
Copy link
Collaborator Author

alex9849 commented Feb 10, 2025

Also one case where parsing fails for me.
When pasing directly into bytes. Some bytes inputs also don't work.

grammar.parse(b'\x04test', NonTerminal("<entry_byte>")).to_bytes() # returns b'\x04test' <-- Works
grammar.parse(b'\x04test\x02', NonTerminal("<entry_byte>")).to_bytes() # returns b'\x04test\x02' <-- Works
grammar.parse(b'\x04test\x02d', NonTerminal("<entry_byte>")).to_bytes() # returns b'\x04test\x02' <-- Last letter missing
grammar.parse(b'\x04test\x02de', NonTerminal("<entry_byte>")).to_bytes() # returns b'\x04test\x02d' <-- Last letter missing

In this case the parser looses one letter when I add a second hexadecimal number to the parsing input.

@andreas-zeller
Copy link
Collaborator

Just to be sure: Is this in .parse() or in .to_bytes()? (Replace .to_bytes() by .value() and report the result)

@alex9849
Copy link
Collaborator Author

Image

Image

This is the result using the two example with .values() instead of .to_bytes()

@andreas-zeller andreas-zeller added prio: medium Medium priority issue status: awaiting integration Task is addressed in a branch labels Feb 10, 2025
@joszamama joszamama removed the status: awaiting integration Task is addressed in a branch label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio: medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants