xguerin / bitstring

OCaml Bitstring - bitstring matching for OCaml
GNU General Public License v2.0
67 stars 8 forks source link

Type casts not recognized in ppx #12

Closed rixed closed 6 years ago

rixed commented 6 years ago

Exemple:

# #require "bitstring";;
# open Bitstring;;
# let x = 42;;
val x : int = 42
# #require "bitstring.ppx";;
# let%bitstring b = {| x : 6 |};;
val b : Bitstring.bitstring = (Bytes.of_string "\168", 0, 6)
# let%bitstring b = {| (x :> int) : 6 |};;
Error: Invalid qualifiers list
xguerin commented 6 years ago

Yes, I can see how :> would be a problem. The parser for the content of {| |} is very primitive and simply splits the verbatim string using the : delimiter. I can probably come up with a workaround for the :> operator.

rixed commented 6 years ago

Your latest patch works for me. But for a last annoying error: comments are not allowed within match%bitstring patterns. Not a big deal but the error message can be a bit confusing.

xguerin commented 6 years ago

comments are not allowed within match%bitstring patterns

Yes, that's to be expected. The parser is quite dumb. I've been pondering over using menhir to make the parser a bit more friendly and ruled against it to avoid having to implement and actual OCaml parser.

Regardless, I'll reopen that question and link your comment to it.

rixed commented 6 years ago

Well, thank you anyway, for answering and fixing the parser so fast for my issue.