Skip to content

Commit

Permalink
Correct the generated bison parser for Bytes (#2620)
Browse files Browse the repository at this point in the history
* Don't enquote Bytes tokens in bison parser

* Add test

Co-authored-by: rv-jenkins <[email protected]>
  • Loading branch information
gtrepta and rv-jenkins authored May 25, 2022
1 parent 93ff45a commit 3158228
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bison_parser
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b"\x00\x0f"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inj{SortBytes{}, SortPgm{}}(\dv{SortBytes{}}("\x00\x0f"))
8 changes: 8 additions & 0 deletions k-distribution/tests/regression-new/kast-bison-bytes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEF=kast-in
EXT=kast-in
TESTDIR=.
KOMPILE_BACKEND=llvm
KAST_FLAGS=--gen-parser
CHECK=| diff -

include ../../../include/kframework/ktest.mak
12 changes: 12 additions & 0 deletions k-distribution/tests/regression-new/kast-bison-bytes/kast-in.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2019 K Team. All Rights Reserved.

module KAST-IN-SYNTAX
imports BYTES-SYNTAX

syntax Pgm ::= Bytes
endmodule

module KAST-IN
imports KAST-IN-SYNTAX
configuration <k> $PGM:Pgm </k>
endmodule
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,15 @@ private static void processProduction(Production prod, Module module, Module dis
" node *n = malloc(sizeof(node));\n" +
" n->symbol = ");
boolean isString = module.sortAttributesFor().get(prod.sort().head()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("").equals("STRING.String");
if (!isString) {
boolean isBytes = module.sortAttributesFor().get(prod.sort().head()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("").equals("BYTES.Bytes");
if (!isString && !isBytes) {
bison.append("enquote(");
}
bison.append("$1.token");
if (!isString) {
if (isBytes) {
bison.append("+1"); // skip the first 'b' char
}
if (!isString && !isBytes) {
bison.append(")");
}
bison.append(";\n" +
Expand Down

0 comments on commit 3158228

Please sign in to comment.