Skip to content

Commit

Permalink
Use Lrama LALR parser generator instead of Bison
Browse files Browse the repository at this point in the history
https://bugs.ruby-lang.org/issues/19637

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
  • Loading branch information
yui-knk and nobu committed May 12, 2023
1 parent d314fe4 commit a1b01e7
Show file tree
Hide file tree
Showing 38 changed files with 5,749 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/baseruby.yml
Expand Up @@ -56,7 +56,7 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler: none
- run: echo "GNUMAKEFLAGS=-j$((1 + $(nproc --all)))" >> $GITHUB_ENV
- run: sudo apt-get install build-essential autoconf bison libyaml-dev
- run: sudo apt-get install build-essential autoconf libyaml-dev
- run: ./autogen.sh
- run: ./configure --disable-install-doc
- run: make common-srcs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bundled_gems.yml
Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
set -x
sudo apt-get update -q || :
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev bison autoconf ruby
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev autoconf ruby
if: ${{ steps.diff.outcome == 'failure' }}

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_dependencies.yml
Expand Up @@ -42,7 +42,7 @@ jobs:
run: |
set -x
sudo apt-get update -q || :
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev bison autoconf ruby
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev autoconf ruby
if: ${{ contains(matrix.os, 'ubuntu') }}
- name: Install libraries
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Expand Up @@ -51,7 +51,7 @@ jobs:
run: |
set -x
sudo apt-get update -q || :
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev bison autoconf ruby
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev autoconf ruby
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/macos.yml
Expand Up @@ -59,12 +59,11 @@ jobs:
- name: Install libraries
run: |
brew upgrade
brew install gmp libffi openssl@1.1 zlib autoconf automake libtool readline bison
brew install gmp libffi openssl@1.1 zlib autoconf automake libtool readline
working-directory: src
- name: Set ENV
run: |
echo "MAKEFLAGS=-j$((1 + $(sysctl -n hw.activecpu)))" >> $GITHUB_ENV
echo "PATH="/usr/local/opt/bison/bin:$PATH"" >> $GITHUB_ENV
for lib in openssl@1.1 readline; do
CONFIGURE_ARGS="${CONFIGURE_ARGS:+$CONFIGURE_ARGS }--with-${lib%@*}-dir=$(brew --prefix $lib)"
done
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mingw.yml
Expand Up @@ -85,7 +85,7 @@ jobs:
mv /c/Windows/System32/libcrypto-1_1-x64.dll /c/Windows/System32/libcrypto-1_1-x64.dll_
mv /c/Windows/System32/libssl-1_1-x64.dll /c/Windows/System32/libssl-1_1-x64.dll_
result=true
for e in gcc.exe ragel.exe make.exe bison.exe libcrypto-1_1-x64.dll libssl-1_1-x64.dll; do
for e in gcc.exe ragel.exe make.exe libcrypto-1_1-x64.dll libssl-1_1-x64.dll; do
echo '##['group']'$'\033[93m'$e$'\033[m'
where $e || result=false
echo '##['endgroup']'
Expand All @@ -96,7 +96,7 @@ jobs:
run: |
# show version
result=true
for e in gcc ragel make bison "openssl version"; do
for e in gcc ragel make "openssl version"; do
case "$e" in *" "*) ;; *) e="$e --version";; esac
echo '##['group']'$'\033[93m'$e$'\033[m'
$e || result=false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rjit-bindgen.yml
Expand Up @@ -53,7 +53,7 @@ jobs:
libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev \
libclang1-10 \
bison autoconf
autoconf
sudo apt-get install -q -y pkg-config || :
- name: Set up Ruby
uses: ruby/setup-ruby@d2b39ad0b52eca07d23f3aa14fdf2a3fcc1f411c # v1.148.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rjit.yml
Expand Up @@ -65,7 +65,7 @@ jobs:
${arch:+cross}build-essential${arch/:/-} \
libssl-dev${arch} libyaml-dev${arch} libreadline6-dev${arch} \
zlib1g-dev${arch} libncurses5-dev${arch} libffi-dev${arch} \
bison autoconf ruby libcapstone-dev
autoconf ruby libcapstone-dev
sudo apt-get install -q -y pkg-config${arch} || :
- name: git config
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Expand Up @@ -70,7 +70,7 @@ jobs:
${arch:+cross}build-essential${arch/:/-} \
libssl-dev${arch} libyaml-dev${arch} libreadline6-dev${arch} \
zlib1g-dev${arch} libncurses5-dev${arch} libffi-dev${arch} \
bison autoconf ruby
autoconf ruby
sudo apt-get install -q -y pkg-config${arch} || :
- name: git config
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm.yml
Expand Up @@ -66,7 +66,7 @@ jobs:
run: |
set -ex
sudo apt-get update -q || :
sudo apt-get install --no-install-recommends -q -y ruby bison make autoconf git wget
sudo apt-get install --no-install-recommends -q -y ruby make autoconf git wget
wasi_sdk_deb="wasi-sdk_${WASI_SDK_VERSION_MAJOR}.${WASI_SDK_VERSION_MINOR}_amd64.deb"
wget "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION_MAJOR}/${wasi_sdk_deb}"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/windows.yml
Expand Up @@ -79,7 +79,6 @@ jobs:
run: |
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH
scoop install winflexbison
shell: pwsh
- name: git config
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yjit-ubuntu.yml
Expand Up @@ -103,7 +103,7 @@ jobs:
run: |
set -x
sudo apt-get update -q || :
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev bison autoconf ruby
sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev autoconf ruby
- name: Install Rust
if: ${{ matrix.rust_version }}
run: rustup install ${{ matrix.rust_version }} --profile minimal
Expand Down
7 changes: 4 additions & 3 deletions common.mk
Expand Up @@ -298,7 +298,8 @@ configure-ext: $(EXTS_MK)

build-ext: $(EXTS_MK)
$(Q)$(MAKE) -f $(EXTS_MK) $(mflags) libdir="$(libdir)" LIBRUBY_EXTS=$(LIBRUBY_EXTS) \
EXTENCS="$(ENCOBJS)" MINIRUBY="$(MINIRUBY)" UPDATE_LIBRARIES=no $(EXTSTATIC)
EXTENCS="$(ENCOBJS)" BASERUBY="$(BASERUBY)" MINIRUBY="$(MINIRUBY)" \
UPDATE_LIBRARIES=no $(EXTSTATIC)
$(Q)$(MAKE) $(EXTS_NOTE)

exts-note: $(EXTS_MK)
Expand Down Expand Up @@ -1208,8 +1209,8 @@ $(srcdir)/ext/ripper/ripper.c: $(srcdir)/ext/ripper/tools/preproc.rb $(srcdir)/p
$(Q) $(CHDIR) $(@D) && \
$(CAT_DEPEND) depend | \
$(exec) $(MAKE) -f - $(mflags) \
Q=$(Q) ECHO=$(ECHO) RM="$(RM1)" BISON="$(YACC)" top_srcdir=../.. srcdir=. VPATH=../.. \
RUBY="$(BASERUBY)" PATH_SEPARATOR="$(PATH_SEPARATOR)" LANG=C
Q=$(Q) ECHO=$(ECHO) RM="$(RM1)" top_srcdir=../.. srcdir=. VPATH=../.. \
RUBY="$(BASERUBY)" BASERUBY="$(BASERUBY)" PATH_SEPARATOR="$(PATH_SEPARATOR)" LANG=C

$(srcdir)/ext/json/parser/parser.c: $(srcdir)/ext/json/parser/parser.rl $(srcdir)/ext/json/parser/prereq.mk
$(ECHO) generating $@
Expand Down
1 change: 1 addition & 0 deletions defs/gmake.mk
@@ -1,6 +1,7 @@
# -*- mode: makefile-gmake; indent-tabs-mode: t -*-

reconfig config.status: export MAKE:=$(MAKE)
export BASERUBY:=$(BASERUBY)
override gnumake_recursive := $(if $(findstring n,$(firstword $(MFLAGS))),,+)
override mflags := $(filter-out -j%,$(MFLAGS))
MSPECOPT += $(if $(filter -j%,$(MFLAGS)),-j)
Expand Down
1 change: 0 additions & 1 deletion doc/contributing/building_ruby.md
Expand Up @@ -15,7 +15,6 @@
If you want to build from the git repository, you will also need:

* autoconf - 2.67 or later
* bison - 3.0 or later
* gperf - 3.1 or later
* Usually unneeded; only if you edit some source files using gperf
* ruby - 2.5 or later
Expand Down
7 changes: 3 additions & 4 deletions doc/windows.md
Expand Up @@ -19,7 +19,7 @@ Ruby core development can be done either in Windows `cmd` like:
```
ridk enable ucrt64
pacman -S --needed bison %MINGW_PACKAGE_PREFIX%-openssl %MINGW_PACKAGE_PREFIX%-libyaml
pacman -S --needed %MINGW_PACKAGE_PREFIX%-openssl %MINGW_PACKAGE_PREFIX%-libyaml
cd c:\
mkdir work
Expand All @@ -38,7 +38,7 @@ or in MSYS2 `bash` like:
ridk enable ucrt64
bash
pacman -S --needed bison $MINGW_PACKAGE_PREFIX-openssl $MINGW_PACKAGE_PREFIX-libyaml
pacman -S --needed $MINGW_PACKAGE_PREFIX-openssl $MINGW_PACKAGE_PREFIX-libyaml
cd /c/
mkdir work
Expand Down Expand Up @@ -78,15 +78,14 @@ make
* dumpbin

4. If you want to build from GIT source, following commands are required.
* bison
* patch
* sed
* ruby 2.0 or later

You can use [scoop](https://scoop.sh/) to install them like:

```
scoop install git ruby winflexbison sed patch
scoop install git ruby sed patch
```

5. You need to install required libraries using [vcpkg](https://vcpkg.io/) like:
Expand Down
2 changes: 2 additions & 0 deletions ext/ripper/depend
@@ -1,6 +1,7 @@
GEN = $(srcdir)/tools/generate.rb
SRC1 = $(top_srcdir)/parse.y
SRC2 = $(srcdir)/eventids2.c
BISON = $(BASERUBY) $(top_srcdir)/tool/lrama/exe/lrama

.SUFFIXES: .y

Expand All @@ -10,6 +11,7 @@ ripper.o: ripper.c

.y.c:
$(ECHO) compiling compiler $<
$(ECHO) $(BISON)
$(Q) $(BISON) -t -v -oy.tab.c $<
$(Q) sed -e "/^#/s!y\.tab\.c!$@!" -f $(top_srcdir)/tool/ytab.sed y.tab.c > $@
@$(RM) y.tab.c
Expand Down
10 changes: 5 additions & 5 deletions ext/ripper/extconf.rb
Expand Up @@ -7,11 +7,11 @@
def main
yacc = ENV["YACC"] || "bison"

unless find_executable(yacc)
unless File.exist?('ripper.c') or File.exist?("#{$srcdir}/ripper.c")
raise 'missing bison; abort'
end
end
# unless find_executable(yacc)
# unless File.exist?('ripper.c') or File.exist?("#{$srcdir}/ripper.c")
# raise 'missing bison; abort'
# end
# end
$objs = %w(ripper.o)
$distcleanfiles.concat %w(ripper.y ripper.c eventids1.c eventids2table.c)
$cleanfiles.concat %w(ripper.E ripper.output y.output .eventids2-check)
Expand Down
2 changes: 1 addition & 1 deletion template/Makefile.in
Expand Up @@ -29,7 +29,7 @@ CPP = @CPP@
LD = @LD@
RUSTC = @RUSTC@
CARGO = @CARGO@
YACC = bison
YACC = $(BASERUBY) $(tooldir)/lrama/exe/lrama
PURIFY =
AUTOCONF = autoconf
CONFIGURE = @CONFIGURE@
Expand Down
7 changes: 7 additions & 0 deletions tool/lrama/exe/lrama
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby


$LOAD_PATH << File.join(__dir__, "../lib")
require "lrama"

Lrama::Command.new.run(ARGV.dup)
13 changes: 13 additions & 0 deletions tool/lrama/lib/lrama.rb
@@ -0,0 +1,13 @@
require "lrama/bitmap"
require "lrama/command"
require "lrama/context"
require "lrama/digraph"
require "lrama/grammar"
require "lrama/lexer"
require "lrama/output"
require "lrama/parser"
require "lrama/report"
require "lrama/states"
require "lrama/states_reporter"
require "lrama/version"
require "lrama/warning"
29 changes: 29 additions & 0 deletions tool/lrama/lib/lrama/bitmap.rb
@@ -0,0 +1,29 @@
module Lrama
module Bitmap
def self.from_array(ary)
bit = 0

ary.each do |int|
bit |= (1 << int)
end

bit
end

def self.to_array(int)
a = []
i = 0

while int > 0 do
if int & 1 == 1
a << i
end

i += 1
int >>= 1
end

a
end
end
end

0 comments on commit a1b01e7

Please sign in to comment.