diff options
author | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-05-12 18:25:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 18:25:10 +0900 |
commit | a1b01e7701f9fc370f8dff777aad6d39a2c5a3e3 (patch) | |
tree | 69bb0c08c139f1c7c5abe9422649f11581f85529 /tool/lrama/lib/lrama/bitmap.rb | |
parent | d314fe42f987fcfaad67f102ec418ee4ca32ee99 (diff) |
Use Lrama LALR parser generator instead of Bisonv3_3_0_preview1
https://bugs.ruby-lang.org/issues/19637
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7798
Merged-By: yui-knk <spiketeika@gmail.com>
Diffstat (limited to 'tool/lrama/lib/lrama/bitmap.rb')
-rw-r--r-- | tool/lrama/lib/lrama/bitmap.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/bitmap.rb b/tool/lrama/lib/lrama/bitmap.rb new file mode 100644 index 0000000000..8349a23c34 --- /dev/null +++ b/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 |