todo: POSIX yacc and prototypes
[bison.git] / tests / d.at
blobd37effbf3f4150cfdf3616a8dc8a00a189597e22
1 # D features tests.                      -*- Autotest -*-
3 # Copyright (C) 2020-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 AT_BANNER([[D Features.]])
20 # AT_CHECK_D_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS], [EXTRA_USER_CODE])
21 # ----------------------------------------------------------------------
22 # Check that a minimal parser with DIRECTIVES compiles in D.
23 # Put the D code in YYParser.d.
24 m4_define([AT_CHECK_D_MINIMAL],
26 AT_DATA([[YYParser.y]], [
27 %language "D"
28 %token END "end"
29 [$1]
31 start: END {$2};
33 [$4]
34 void main() {}
36 AT_BISON_CHECK([[-Wno-deprecated YYParser.y]])
37 AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
38 AT_COMPILE_D([[YYParser]])
41 # AT_CHECK_D_MINIMAL_W_LEXER([1:DIRECTIVES],
42 #       [2:YYLEX_ACTION], [3:LEXER_BODY], [4:PARSER_ACTION], [5:VALUE_TYPE],
43 #       [6:POSITION_TYPE], [7:LOCATION_TYPE])
44 # ---------------------------------------------------------------------
45 # Check that a minimal parser with DIRECTIVES and a body for yylex()
46 # compiles in D.
47 m4_define([AT_CHECK_D_MINIMAL_W_LEXER],
48 [AT_CHECK_D_MINIMAL([$1], [], [], [
50 import std.range.primitives;
51 import std.stdio;
53 auto calcLexer(R)(R range)
54   if (isInputRange!R && is (ElementType!R : dchar))
56   return new CalcLexer!R(range);
59 auto calcLexer (File f)
61   import std.algorithm : map, joiner;
62   import std.utf : byDchar;
64   return f.byChunk(1024)        // avoid making a syscall roundtrip per char
65           .map!(chunk => cast(char[]) chunk) // because byChunk returns ubyte[]
66           .joiner               // combine chunks into a single virtual range of char
67           .calcLexer;           // forward to other overload
70 class CalcLexer(R) : Lexer
71   if (isInputRange!R && is (ElementType!R : dchar))
73   R input;
75   this(R r) {
76     input = r;
77   }
79   void yyerror(string s) {}
81   Symbol yylex()
82   {
83     $2
84   }
88   $3
89 ], [$4], [$6])])
91 # AT_CHECK_D_GREP([LINE], [COUNT=1])
92 # -------------------------------------
93 # Check that YYParser.d contains exactly COUNT lines matching ^LINE$
94 # with grep.
95 m4_define([AT_CHECK_D_GREP],
96 [AT_CHECK([grep -c '^$1$' YYParser.d], [ignore], [m4_default([$2], [1])
97 ])])
99 ## -------------------------------------- ##
100 ## D parser class extends and implements. ##
101 ## -------------------------------------- ##
103 AT_SETUP([D parser class extends and implements])
104 AT_KEYWORDS([d])
106 AT_CHECK_D_MINIMAL([])
107 AT_CHECK_D_GREP([[class YYParser]])
109 AT_CHECK_D_MINIMAL([%define api.parser.extends {BaseClass}], [], [], [class BaseClass {}])
110 AT_CHECK_D_GREP([[class YYParser : BaseClass]])
112 AT_CHECK_D_MINIMAL([%define api.parser.extends {Interface}], [], [], [interface Interface {}])
113 AT_CHECK_D_GREP([[class YYParser : Interface]])
115 AT_CHECK_D_MINIMAL(
116 [%define api.parser.extends {BaseClass}
117 %define api.parser.implements {Interface}], [], [],
118 [class BaseClass {}
119 interface Interface {}
121 AT_CHECK_D_GREP([[class YYParser : BaseClass, Interface]])
123 AT_CHECK_D_MINIMAL(
124 [%define api.parser.extends {BaseClass}
125 %define api.parser.implements {Interface1, Interface2}], [], [],
126 [class BaseClass {}
127 interface Interface1 {}
128 interface Interface2 {}
130 AT_CHECK_D_GREP([[class YYParser : BaseClass, Interface1, Interface2]])
132 AT_CLEANUP
134 ## --------------------------------------------- ##
135 ## D parser class api.token.raw true by default. ##
136 ## --------------------------------------------- ##
138 AT_SETUP([D parser class api.token.raw true by default])
139 AT_KEYWORDS([d])
141 AT_CHECK_D_MINIMAL_W_LEXER([
142 %define api.token.raw true
143 %union { int ival; }], [return Symbol(TokenKind.END);])
144 AT_CHECK_D_GREP([[  END = 3,]])
146 AT_CHECK_D_MINIMAL_W_LEXER([
147 %define api.token.raw false
148 %union { int ival; }], [return Symbol(TokenKind.END);])
149 AT_CHECK_D_GREP([[  END = 258,]])
151 AT_CHECK_D_MINIMAL_W_LEXER([
152 %union { int ival; }], [return Symbol(TokenKind.END);])
153 AT_CHECK_D_GREP([[  END = 3,]])
155 AT_CLEANUP