fix: noconfirm auto-selects first AUR match

This commit is contained in:
2026-05-08 11:01:02 +01:00
parent d39cdc3fd9
commit 153cca6132
8056 changed files with 1983098 additions and 779 deletions
@@ -0,0 +1,31 @@
# Examples in D
This directory contains examples of Bison grammar files in D.
You can run `make` to compile these examples. And `make clean` to tidy
afterwards.
## d/simple.y
The usual calculator.
## d/calc.y
A richer implementation of the calculator, with location tracking.
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2021 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
# LocalWords: mfcalc calc parsers yy
--->
@@ -0,0 +1,20 @@
# This Makefile is designed to be simple and readable. It does not
# aim at portability. It requires GNU Make.
BISON = bison
DC = dmd
all: calc
%.d %.html %.gv: %.y
$(BISON) $(BISONFLAGS) --html --graph -o $*.d $<
%: %.d
$(DC) $(DCFLAGS) $<
run: calc
@echo "Type arithmetic expressions. Quit with ctrl-d."
./$<
clean:
rm -f calc calc.d calc.xml calc.gv calc.html *.o
@@ -0,0 +1,51 @@
#! /bin/sh
# Copyright (C) 2018-2021 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF
1 + 2 * 3
EOF
run 0 7
cat >input <<EOF
+1 + +2 * +3
EOF
run 0 7
cat >input <<EOF
-1 + -2 * -3
EOF
run 0 5
cat >input <<EOF
1 + 2 * * 3
EOF
run 1 "err: 1.9: syntax error, unexpected *, expecting + or - or ( or number"
cat >input <<EOF
1111 + 1111 2222
EOF
run 1 "err: 1.13-16: syntax error, unexpected number"
cat >input <<EOF
1 +
EOF
run 1 "err: 1.4-2.0: syntax error, unexpected end of line, expecting + or - or ( or number"
cat >input <<EOF
99 009
EOF
run 1 "err: 1.4-6: syntax error, unexpected number"
@@ -0,0 +1,188 @@
/* Parser and scanner for calc in D. -*- D -*-
Copyright (C) 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
%language "D"
%define api.parser.class {Calc}
%define api.push-pull push
%define api.token.constructor
%define api.value.type union
%define parse.error detailed
%define parse.trace
%locations
/* Bison Declarations */
%token PLUS "+"
MINUS "-"
STAR "*"
SLASH "/"
LPAR "("
RPAR ")"
EOL "end of line"
%token <int> NUM "number"
%type <int> exp
%printer { yyo.write($$); } <int>
%left "-" "+"
%left "*" "/"
%precedence UNARY /* unary operators */
/* Grammar follows */
%%
input:
line
| input line
;
line:
EOL
| exp EOL { writeln ($exp); }
| error EOL { yyerrok(); }
;
exp:
NUM { $$ = $1; }
| exp "+" exp { $$ = $1 + $3; }
| exp "-" exp { $$ = $1 - $3; }
| exp "*" exp { $$ = $1 * $3; }
| exp "/" exp { $$ = $1 / $3; }
| "+" exp %prec UNARY { $$ = $2; }
| "-" exp %prec UNARY { $$ = -$2; }
| "(" exp ")" { $$ = $2; }
;
%%
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; }
Location location;
// Should be a local in main, shared with %parse-param.
int exit_status = 0;
void yyerror(const Location loc, string s)
{
exit_status = 1;
stderr.writeln(loc.toString(), ": ", s);
}
Symbol yylex()
{
import std.uni : isWhite, isNumber;
// Skip initial spaces
while (!input.empty && input.front != '\n' && isWhite(input.front))
{
location.end.column++;
input.popFront;
}
location.step();
if (input.empty)
return Symbol.YYEOF(location);
// Numbers.
if (input.front.isNumber)
{
import std.compiler : version_minor;
static if (version_minor >= 95)
{
// from Dlang v2.095.0 onwards std.conv.parse reports
// the number of consumed characters
import std.typecons : Flag, Yes;
import std.conv : parse;
auto parsed = parse!(int, R, Yes.doCount)(input);
int ival = parsed.data;
location.end.column += cast(int) parsed.count;
}
else
{
auto copy = input;
import std.conv : parse;
int ival = input.parse!int;
while (!input.empty && copy.front != input.front)
{
location.end.column++;
copy.popFront;
}
}
return Symbol.NUM(ival, location);
}
// Individual characters
auto ch = input.front;
input.popFront;
location.end.column++;
switch (ch)
{
case '+': return Symbol.PLUS(location);
case '-': return Symbol.MINUS(location);
case '*': return Symbol.STAR(location);
case '/': return Symbol.SLASH(location);
case '(': return Symbol.LPAR(location);
case ')': return Symbol.RPAR(location);
case '\n':
{
location.end.line++;
location.end.column = 1;
return Symbol.EOL(location);
}
default: assert(0);
}
}
}
int main()
{
auto l = calcLexer(stdin);
auto p = new Calc(l);
import core.stdc.stdlib : getenv;
if (getenv("YYDEBUG"))
p.setDebugLevel(1);
int status;
do {
status = p.pushParse(l.yylex());
} while (status == PUSH_MORE);
return l.exit_status;
}
@@ -0,0 +1,36 @@
## Copyright (C) 2018-2021 Free Software Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
calcddir = $(docdir)/%D%
## ------ ##
## Calc. ##
## ------ ##
if ENABLE_D
check_SCRIPTS += %D%/calc
TESTS += %D%/calc.test
endif
EXTRA_DIST += %D%/calc.test
%D%/calc.d: %D%/calc.y $(dependencies)
$(AM_V_GEN)$(MKDIR_P) %D%
$(AM_V_at)$(BISON) -o $@ $(srcdir)/%D%/calc.y
%D%/calc: %D%/calc.d
$(AM_V_GEN) $(DC) $(DCFLAGS) -of$@ %D%/calc.d
dist_calcd_DATA = %D%/calc.y %D%/Makefile
CLEANFILES += %D%/calc %D%/calc.[do]
@@ -0,0 +1,20 @@
## Copyright (C) 2018-2021 Free Software Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
ddir = $(docdir)/%D%
dist_d_DATA = %D%/README.md
include %D%/calc/local.mk
include %D%/simple/local.mk
@@ -0,0 +1,20 @@
# This Makefile is designed to be simple and readable. It does not
# aim at portability. It requires GNU Make.
BISON = bison
DC = dmd
all: calc
%.d %.html %.gv: %.y
$(BISON) $(BISONFLAGS) --html --graph -o $*.d $<
%: %.d
$(DC) $(DCFLAGS) $<
run: calc
@echo "Type arithmetic expressions. Quit with ctrl-d."
./$<
clean:
rm -f calc calc.d calc.xml calc.gv calc.html *.o
@@ -0,0 +1,36 @@
#! /bin/sh
# Copyright (C) 2018-2021 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF
1 + 2 * 3
EOF
run 0 7
cat >input <<EOF
+1 + +2 * +3
EOF
run 0 7
cat >input <<EOF
-1 + -2 * -3
EOF
run 0 5
cat >input <<EOF
1 + 2 * * 3
EOF
run 1 "err: syntax error, unexpected *, expecting + or - or ( or number"
@@ -0,0 +1,146 @@
/* Parser and scanner for calc in D. -*- D -*-
Copyright (C) 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
%language "D"
%define api.parser.class {Calc}
%define parse.error detailed
%union {
int ival;
}
/* Bison Declarations */
%token PLUS "+"
MINUS "-"
STAR "*"
SLASH "/"
LPAR "("
RPAR ")"
EOL "end of line"
%token <ival> NUM "number"
%type <ival> exp
%left "-" "+"
%left "*" "/"
%precedence UNARY /* unary operators */
/* Grammar follows */
%%
input:
line
| input line
;
line:
EOL
| exp EOL { writeln ($exp); }
| error EOL { yyerrok(); }
;
exp:
NUM { $$ = $1; }
| exp "+" exp { $$ = $1 + $3; }
| exp "-" exp { $$ = $1 - $3; }
| exp "*" exp { $$ = $1 * $3; }
| exp "/" exp { $$ = $1 / $3; }
| "+" exp %prec UNARY { $$ = $2; }
| "-" exp %prec UNARY { $$ = -$2; }
| "(" exp ")" { $$ = $2; }
;
%%
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; }
// Should be a local in main, shared with %parse-param.
int exit_status = 0;
public void yyerror(string s)
{
exit_status = 1;
stderr.writeln(s);
}
Symbol yylex()
{
import std.uni : isWhite, isNumber;
// Skip initial spaces
while (!input.empty && input.front != '\n' && isWhite(input.front))
input.popFront;
if (input.empty)
return Symbol(TokenKind.YYEOF);
// Numbers.
if (input.front.isNumber)
{
import std.conv : parse;
return Symbol(TokenKind.NUM, input.parse!int);
}
// Individual characters
auto ch = input.front;
input.popFront;
switch (ch)
{
case '+': return Symbol(TokenKind.PLUS);
case '-': return Symbol(TokenKind.MINUS);
case '*': return Symbol(TokenKind.STAR);
case '/': return Symbol(TokenKind.SLASH);
case '(': return Symbol(TokenKind.LPAR);
case ')': return Symbol(TokenKind.RPAR);
case '\n': return Symbol(TokenKind.EOL);
default: assert(0);
}
}
}
int main()
{
auto l = calcLexer(stdin);
auto p = new Calc(l);
p.parse();
return l.exit_status;
}
@@ -0,0 +1,36 @@
## Copyright (C) 2018-2021 Free Software Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
simpleddir = $(docdir)/%D%
## ------ ##
## Calc. ##
## ------ ##
if ENABLE_D
check_SCRIPTS += %D%/calc
TESTS += %D%/calc.test
endif
EXTRA_DIST += %D%/calc.test
%D%/calc.d: %D%/calc.y $(dependencies)
$(AM_V_GEN)$(MKDIR_P) %D%
$(AM_V_at)$(BISON) -o $@ $(srcdir)/%D%/calc.y
%D%/calc: %D%/calc.d
$(AM_V_GEN) $(DC) $(DCFLAGS) -of$@ %D%/calc.d
dist_simpled_DATA = %D%/calc.y %D%/Makefile
CLEANFILES += %D%/calc %D%/calc.[do]