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

Correct the generated bison parser for Bytes #2620

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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