##
##  kelbt.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         kelbt
Summary:      Backtracking LALR(1) Parser Generator
URL:          http://www.colm.net/open-source/kelbt/
Vendor:       Adrian Thurston
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        CompilerCompiler
License:      GPL
Version:      0.15
Release:      20150927

#   list of sources
Source0:      http://www.colm.net/files/kelbt/kelbt-%{version}.tar.gz
Patch0:       kelbt.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101

%description
    Kelbt generates backtracking LALR(1) parsers. Where traditional
    LALR(1) parser generators require static resolution of shift/reduce
    conflicts, Kelbt generates parsers that handle conflicts by
    backtracking at runtime. Kelbt is able to generate a parser for any
    context-free grammar that is free of hidden left recursion. Kelbt
    is different from other backtracking LR systems in two ways. First,
    it introduces a class of actions called undo actions. These actions
    are invoked as the backtracker undoes parsing and allow the user
    to revert any side effects of forward semantic actions. This makes
    it possible to backtrack over language constructs that must modify
    global state in preparation for handling context dependencies.
    Second, Kelbt enables a user-controlled parsing strategy that
    approximates that of generalized recursive-descent parsing with
    ordered choice. This makes it easy for the user to resolve language
    ambiguities by ordering the grammar productions of a non-terminal
    according to precedence. It is approximate in the sense that for
    most grammars the equivalent of an ordered choice parsing strategy
    is achieved. In cases where productions are parsed out of the order
    given, there is a simple grammar transformation that remedies the
    problem.

%track
    prog kelbt = {
        version   = %{version}
        url       = http://www.complang.org/kelbt/
        regex     = kelbt-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    CC="%{l_cc} %{l_cflags -O}" \
    CXX="%{l_cxx} %{l_cxxflags -O}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix}
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install \
        prefix=$RPM_BUILD_ROOT%{l_prefix}
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1
    %{l_shtool} install -c -m 644 \
        kelbt.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

