question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bytes causing parse errors

See original GitHub issue

I’m having issues with working with the Bytes sort. I get parse errors when using Bytes that I don’t get when using a regular Int, for example.

Minimal working example:

require "domains.k"

module BYTES-ISSUE
  imports DOMAINS
  imports BYTES

    syntax Map ::= Map "[" Int ":=" Bytes "]" [function]
 // ----------------------------------------------------
    rule BM[ N := nilBytes ] => BM
    rule BM[ N := (B : BS) ] => (BM[N <- B])[N +Int 1 := BS]
endmodule

This gives output:

kompile bytes-issue.k
[Error] Compiler: Had 2 parsing errors.
[Error] Inner Parser: Parse error: unexpected token ':'.
	Source(/home/hjort/code/wasm/k-demos/bad_error_msg/./no-square-bracket.k)
	Location(10,22,10,23)
[Error] Inner Parser: Parse error: unexpected token ']'.
	Source(/home/hjort/code/wasm/k-demos/bad_error_msg/./no-square-bracket.k)
	Location(9,28,9,29)
[Warning] Compiler: Could not find main syntax module with name ...

The problem persists when I remove one of the rules (although one parse error then goes away, of course), and if I change the square brackets to parentheses, and the := to something like <-.

The problem goes away if I change to using some other sort, like by defining Ints:

require "domains.k"

module BYTES-ISSUE
  imports DOMAINS
  imports BYTES

    syntax Ints ::= ".Ints" | Int ":" Ints      // Added line
    syntax Map  ::= Map "[" Int ":=" Ints "]"   // Bytes => Ints
 // -----------------------------------------
    rule BM[ N := .Ints ] => BM                 // nilBytes => Ints
    rule BM[ N := (B : BS) ] => (BM[N <- B])[N +Int 1 := BS]
endmodule

The problem also goes away for the first rule if I change from using nilBytes to .Bytes, which I find strange.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
dwightguthcommented, Mar 6, 2019

One feature we may consider adding to k is explicitly annotating the syntax exported by a module, but nothing like this has been created yet.

1reaction
dwightguthcommented, Mar 6, 2019

The productions in the BYTES-IN-K module are not a part of the public interface of the Bytes type and will not work in the ocaml or llvm backends. If you want to use the BYTES module, you should only rely on the functions in the BYTES-HOOKED module. If you just want a cons list, I’d recommend implementing it yourself, but note that the BYTES sort is memory efficient and has constant time update and lookup, which cannot be said of a cons list of ints.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Byte Order Mark in JSON data can cause parsing error ... - IBM
If the JSON data contains a Byte Order Mark (BOM) to indicate data encoding, then the JSON data may not actually be valid....
Read more >
parser error, 0 of 4344 bytes parsed (Node.js) - Stack Overflow
The error is caused only when i use loadUser function, if i remove the loadUser Funciton everything is working fine. I don't know...
Read more >
SQL*Developer Monitoring Tool Cause Too Many Parse Errors
Oracle Database - Standard Edition - Version 12.2.0.1 and later: SQL*Developer Monitoring Tool Cause Too Many Parse Errors.
Read more >
Solved: Error message help: webauthRedirect Parse Error
Solved: I'm seeing these messages show up in the Message Log over and over. I can't find much info on them. *webauthRedirect: Mar...
Read more >
Apache Spark job fails with Failed to parse byte string
Problem. Spark-submit jobs fail with a Failed to parse byte string: -1 error message. Console Copy. java. · Cause. The value of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found