summaryrefslogtreecommitdiff
path: root/tests/d.at
diff options
context:
space:
mode:
authorAdela Vais <adela.vais99@gmail.com>2020-10-03 17:01:14 +0300
committerAkim Demaille <akim.demaille@gmail.com>2020-10-03 17:17:32 +0200
commit7cd195b30aa615fa9996f471c1f200e016a904a5 (patch)
tree8d9ac717a3cb1e3746b2fdd811d32349e7af15a7 /tests/d.at
parente66673aa64aae0e5422e780abea9cbcb99b7731e (diff)
downloadbison-7cd195b30aa615fa9996f471c1f200e016a904a5.tar.gz
d: change api.token.raw default value to true
Generate consecutive values for enum TokenKind, as D's yylex() returns TokenKind and collisions can't happen. * data/skeletons/d.m4: Change default value. * tests/scanner.at, tests/d.at: Check it.
Diffstat (limited to 'tests/d.at')
-rw-r--r--tests/d.at76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/d.at b/tests/d.at
index d38e8130..5ed45ee5 100644
--- a/tests/d.at
+++ b/tests/d.at
@@ -38,6 +38,59 @@ AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
AT_COMPILE_D([[YYParser]])
])
+# AT_CHECK_D_MINIMAL_W_LEXER([1:DIRECTIVES],
+# [2:YYLEX_ACTION], [3:LEXER_BODY], [4:PARSER_ACTION], [5:VALUE_TYPE],
+# [6:POSITION_TYPE], [7:LOCATION_TYPE])
+# ---------------------------------------------------------------------
+# Check that a minimal parser with DIRECTIVES and a body for yylex()
+# compiles in D.
+m4_define([AT_CHECK_D_MINIMAL_W_LEXER],
+[AT_CHECK_D_MINIMAL([$1], [], [], [
+
+import std.range.primitives;
+import std.stdio;
+
+auto calcLexer(R)(R range)
+ if (isInputRange!R && is (ElementType!R : dchar))
+{
+ return new CalcLexer!R(range);
+}
+
+auto calcLexer (File f)
+{
+ import std.algorithm : map, joiner;
+ import std.utf : byDchar;
+
+ return f.byChunk(1024) // avoid making a syscall roundtrip per char
+ .map!(chunk => cast(char[]) chunk) // because byChunk returns ubyte[]
+ .joiner // combine chunks into a single virtual range of char
+ .calcLexer; // forward to other overload
+}
+
+class CalcLexer(R) : Lexer
+ if (isInputRange!R && is (ElementType!R : dchar))
+{
+ R input;
+
+ this(R r) {
+ input = r;
+ }
+
+ void yyerror(string s) {}
+
+ YYSemanticType semanticVal_;
+ YYSemanticType semanticVal() @property { return semanticVal_; }
+
+ TokenKind yylex()
+ {
+ $2
+ }
+}
+]
+[
+ $3
+], [$4], [$6])])
+
# AT_CHECK_D_GREP([LINE], [COUNT=1])
# -------------------------------------
# Check that YYParser.d contains exactly COUNT lines matching ^LINE$
@@ -80,3 +133,26 @@ interface Interface2 {}
AT_CHECK_D_GREP([[class YYParser : BaseClass, Interface1, Interface2]])
AT_CLEANUP
+
+## --------------------------------------------- ##
+## D parser class api.token.raw true by default. ##
+## --------------------------------------------- ##
+
+AT_SETUP([D parser class api.token.raw true by default])
+AT_KEYWORDS([d])
+
+AT_CHECK_D_MINIMAL_W_LEXER([
+%define api.token.raw true
+%union { int ival; }], [return TokenKind.END;])
+AT_CHECK_D_GREP([[ END = 3,]])
+
+AT_CHECK_D_MINIMAL_W_LEXER([
+%define api.token.raw false
+%union { int ival; }], [return TokenKind.END;])
+AT_CHECK_D_GREP([[ END = 258,]])
+
+AT_CHECK_D_MINIMAL_W_LEXER([
+%union { int ival; }], [return TokenKind.END;])
+AT_CHECK_D_GREP([[ END = 3,]])
+
+AT_CLEANUP