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]], [
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()
47 m4_define([AT_CHECK_D_MINIMAL_W_LEXER],
48 [AT_CHECK_D_MINIMAL([$1], [], [], [
50 import std.range.primitives;
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))
79 void yyerror(string s) {}
91 # AT_CHECK_D_GREP([LINE], [COUNT=1])
92 # -------------------------------------
93 # Check that YYParser.d contains exactly COUNT lines matching ^LINE$
95 m4_define([AT_CHECK_D_GREP],
96 [AT_CHECK([grep -c '^$1$' YYParser.d], [ignore], [m4_default([$2], [1])
99 ## -------------------------------------- ##
100 ## D parser class extends and implements. ##
101 ## -------------------------------------- ##
103 AT_SETUP([D parser class extends and implements])
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]])
116 [%define api.parser.extends {BaseClass}
117 %define api.parser.implements {Interface}], [], [],
119 interface Interface {}
121 AT_CHECK_D_GREP([[class YYParser : BaseClass, Interface]])
124 [%define api.parser.extends {BaseClass}
125 %define api.parser.implements {Interface1, Interface2}], [], [],
127 interface Interface1 {}
128 interface Interface2 {}
130 AT_CHECK_D_GREP([[class YYParser : BaseClass, Interface1, Interface2]])
134 ## --------------------------------------------- ##
135 ## D parser class api.token.raw true by default. ##
136 ## --------------------------------------------- ##
138 AT_SETUP([D parser class api.token.raw true by default])
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,]])