From c335174e4bcebf5186e113e2dbb8125e50b96e4b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 28 May 2024 02:13:53 +0900 Subject: [PATCH] Apply frozen string literal magic comment Starting with Ruby 3.4, there is a gradual plan to freeze strings: https://bugs.ruby-lang.org/issues/20205#note-35 Using Ruby 3.4dev with code prior to this PR results in the following warning: ```console $ cd path/to/ruby/lrama $ ruby -v ruby 3.4.0dev (2024-05-27T01:45:38Z master 5853a38043) [x86_64-darwin23] $ RUBYOPT=-W:deprecated bundle exec rake (snip) /Users/koic/src/github.com/ruby/lrama/lib/lrama/output.rb:74: warning: literal string will be frozen in the future ``` This warning suggests that applying the frozen string magic comment will lead to `FrozenError`. So, this indicates that the future behavior of (default frozen) string will produce `FrozenError`. This PR applies the frozen string magic comment to detect `FrozenError` and uses `String#dup` to prevent it: https://gist.github.com/fxn/bf4eed2505c76f4fca03ab48c43adc72#ruby-34 This ensures compatibility for the future. NOTE: From Ruby 3.3+, there is no speed difference between `String#+@` and `String#dup`. For readability, `String#dup` has been chosen: https://github.com/ruby/ruby/pull/8952 --- Gemfile | 2 ++ Rakefile | 2 ++ Steepfile | 2 ++ exe/lrama | 1 + lib/lrama.rb | 2 ++ lib/lrama/bitmap.rb | 2 ++ lib/lrama/command.rb | 2 ++ lib/lrama/context.rb | 2 ++ lib/lrama/counterexamples.rb | 2 ++ lib/lrama/counterexamples/derivation.rb | 2 ++ lib/lrama/counterexamples/example.rb | 2 ++ lib/lrama/counterexamples/path.rb | 2 ++ lib/lrama/counterexamples/production_path.rb | 2 ++ lib/lrama/counterexamples/start_path.rb | 2 ++ lib/lrama/counterexamples/state_item.rb | 2 ++ lib/lrama/counterexamples/transition_path.rb | 2 ++ lib/lrama/counterexamples/triple.rb | 2 ++ lib/lrama/digraph.rb | 2 ++ lib/lrama/grammar.rb | 2 ++ lib/lrama/grammar/auxiliary.rb | 2 ++ lib/lrama/grammar/binding.rb | 2 ++ lib/lrama/grammar/code.rb | 2 ++ lib/lrama/grammar/code/destructor_code.rb | 2 ++ lib/lrama/grammar/code/initial_action_code.rb | 2 ++ lib/lrama/grammar/code/no_reference_code.rb | 2 ++ lib/lrama/grammar/code/printer_code.rb | 2 ++ lib/lrama/grammar/code/rule_action.rb | 2 ++ lib/lrama/grammar/counter.rb | 2 ++ lib/lrama/grammar/destructor.rb | 2 ++ lib/lrama/grammar/error_token.rb | 2 ++ lib/lrama/grammar/parameterizing_rule.rb | 2 ++ .../grammar/parameterizing_rule/resolver.rb | 2 ++ lib/lrama/grammar/parameterizing_rule/rhs.rb | 2 ++ lib/lrama/grammar/parameterizing_rule/rule.rb | 2 ++ lib/lrama/grammar/percent_code.rb | 2 ++ lib/lrama/grammar/precedence.rb | 2 ++ lib/lrama/grammar/printer.rb | 2 ++ lib/lrama/grammar/reference.rb | 2 ++ lib/lrama/grammar/rule.rb | 2 ++ lib/lrama/grammar/rule_builder.rb | 2 ++ lib/lrama/grammar/symbol.rb | 2 ++ lib/lrama/grammar/symbols.rb | 2 ++ lib/lrama/grammar/symbols/resolver.rb | 2 ++ lib/lrama/grammar/type.rb | 2 ++ lib/lrama/grammar/union.rb | 2 ++ lib/lrama/lexer.rb | 2 ++ lib/lrama/lexer/grammar_file.rb | 2 ++ lib/lrama/lexer/location.rb | 2 ++ lib/lrama/lexer/token.rb | 2 ++ lib/lrama/lexer/token/char.rb | 2 ++ lib/lrama/lexer/token/ident.rb | 2 ++ lib/lrama/lexer/token/instantiate_rule.rb | 2 ++ lib/lrama/lexer/token/tag.rb | 2 ++ lib/lrama/lexer/token/user_code.rb | 2 ++ lib/lrama/option_parser.rb | 2 ++ lib/lrama/options.rb | 2 ++ lib/lrama/output.rb | 24 ++++++++++--------- lib/lrama/report.rb | 2 ++ lib/lrama/report/duration.rb | 2 ++ lib/lrama/report/profile.rb | 2 ++ lib/lrama/state.rb | 2 ++ lib/lrama/state/reduce.rb | 2 ++ lib/lrama/state/reduce_reduce_conflict.rb | 2 ++ lib/lrama/state/resolved_conflict.rb | 2 ++ lib/lrama/state/shift.rb | 2 ++ lib/lrama/state/shift_reduce_conflict.rb | 2 ++ lib/lrama/states.rb | 2 ++ lib/lrama/states/item.rb | 2 ++ lib/lrama/states_reporter.rb | 2 ++ lib/lrama/version.rb | 2 ++ lib/lrama/warning.rb | 2 ++ lrama.gemspec | 2 ++ spec/lrama/bitmap_spec.rb | 2 ++ spec/lrama/command_spec.rb | 2 ++ spec/lrama/context_spec.rb | 2 ++ spec/lrama/counterexamples_spec.rb | 4 +++- spec/lrama/grammar/code_spec.rb | 2 ++ spec/lrama/grammar/rule_builder_spec.rb | 2 ++ spec/lrama/grammar/symbol_spec.rb | 2 ++ spec/lrama/grammar/symbols/resolver_spec.rb | 2 ++ spec/lrama/integration_spec.rb | 2 ++ spec/lrama/lexer/location_spec.rb | 2 ++ spec/lrama/lexer/token/user_code_spec.rb | 2 ++ spec/lrama/lexer_spec.rb | 2 ++ spec/lrama/option_parser_spec.rb | 2 ++ spec/lrama/output_spec.rb | 2 ++ spec/lrama/parser_spec.rb | 2 ++ spec/lrama/states_spec.rb | 24 ++++++++++--------- spec/spec_helper.rb | 2 ++ 89 files changed, 200 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 9ae5b9fd..25a46709 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index eb99f009..1e4bf8bd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" namespace "build" do diff --git a/Steepfile b/Steepfile index 4bf2d153..63ac6706 100644 --- a/Steepfile +++ b/Steepfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # D = Steep::Diagnostic # target :lib do diff --git a/exe/lrama b/exe/lrama index ba5fb06c..1aece5d1 100755 --- a/exe/lrama +++ b/exe/lrama @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true $LOAD_PATH << File.join(__dir__, "../lib") require "lrama" diff --git a/lib/lrama.rb b/lib/lrama.rb index 3a1c0981..08c73dec 100644 --- a/lib/lrama.rb +++ b/lib/lrama.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "lrama/bitmap" require_relative "lrama/command" require_relative "lrama/context" diff --git a/lib/lrama/bitmap.rb b/lib/lrama/bitmap.rb index 8349a23c..23cbd30d 100644 --- a/lib/lrama/bitmap.rb +++ b/lib/lrama/bitmap.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama module Bitmap def self.from_array(ary) diff --git a/lib/lrama/command.rb b/lib/lrama/command.rb index 12fc4fc7..17434a04 100644 --- a/lib/lrama/command.rb +++ b/lib/lrama/command.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Command LRAMA_LIB = File.realpath(File.join(File.dirname(__FILE__))) diff --git a/lib/lrama/context.rb b/lib/lrama/context.rb index 3833766c..6eaa771e 100644 --- a/lib/lrama/context.rb +++ b/lib/lrama/context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "report/duration" module Lrama diff --git a/lib/lrama/counterexamples.rb b/lib/lrama/counterexamples.rb index 198741f6..f6510c64 100644 --- a/lib/lrama/counterexamples.rb +++ b/lib/lrama/counterexamples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "set" require_relative "counterexamples/derivation" diff --git a/lib/lrama/counterexamples/derivation.rb b/lib/lrama/counterexamples/derivation.rb index 691e9353..423e58b8 100644 --- a/lib/lrama/counterexamples/derivation.rb +++ b/lib/lrama/counterexamples/derivation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class Derivation diff --git a/lib/lrama/counterexamples/example.rb b/lib/lrama/counterexamples/example.rb index 62244a77..8dda0d17 100644 --- a/lib/lrama/counterexamples/example.rb +++ b/lib/lrama/counterexamples/example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class Example diff --git a/lib/lrama/counterexamples/path.rb b/lib/lrama/counterexamples/path.rb index edba67a3..243b6b42 100644 --- a/lib/lrama/counterexamples/path.rb +++ b/lib/lrama/counterexamples/path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class Path diff --git a/lib/lrama/counterexamples/production_path.rb b/lib/lrama/counterexamples/production_path.rb index d7db6885..0a230c7f 100644 --- a/lib/lrama/counterexamples/production_path.rb +++ b/lib/lrama/counterexamples/production_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class ProductionPath < Path diff --git a/lib/lrama/counterexamples/start_path.rb b/lib/lrama/counterexamples/start_path.rb index 4a6821cd..c0351c82 100644 --- a/lib/lrama/counterexamples/start_path.rb +++ b/lib/lrama/counterexamples/start_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class StartPath < Path diff --git a/lib/lrama/counterexamples/state_item.rb b/lib/lrama/counterexamples/state_item.rb index 930ff4a5..c9198183 100644 --- a/lib/lrama/counterexamples/state_item.rb +++ b/lib/lrama/counterexamples/state_item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class StateItem < Struct.new(:state, :item) diff --git a/lib/lrama/counterexamples/transition_path.rb b/lib/lrama/counterexamples/transition_path.rb index 96e61161..47bfbc4f 100644 --- a/lib/lrama/counterexamples/transition_path.rb +++ b/lib/lrama/counterexamples/transition_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples class TransitionPath < Path diff --git a/lib/lrama/counterexamples/triple.rb b/lib/lrama/counterexamples/triple.rb index e802becc..64014ee2 100644 --- a/lib/lrama/counterexamples/triple.rb +++ b/lib/lrama/counterexamples/triple.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Counterexamples # s: state diff --git a/lib/lrama/digraph.rb b/lib/lrama/digraph.rb index bbaa8601..d2bb8810 100644 --- a/lib/lrama/digraph.rb +++ b/lib/lrama/digraph.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama # Algorithm Digraph of https://dl.acm.org/doi/pdf/10.1145/69622.357187 (P. 625) class Digraph diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index 02ebbb03..4690bcb3 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "forwardable" require_relative "grammar/auxiliary" require_relative "grammar/binding" diff --git a/lib/lrama/grammar/auxiliary.rb b/lib/lrama/grammar/auxiliary.rb index 933574b0..2bacee6f 100644 --- a/lib/lrama/grammar/auxiliary.rb +++ b/lib/lrama/grammar/auxiliary.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar # Grammar file information not used by States but by Output diff --git a/lib/lrama/grammar/binding.rb b/lib/lrama/grammar/binding.rb index e5ea3fb0..2093a8c5 100644 --- a/lib/lrama/grammar/binding.rb +++ b/lib/lrama/grammar/binding.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Binding diff --git a/lib/lrama/grammar/code.rb b/lib/lrama/grammar/code.rb index ab49166a..b6c1cc49 100644 --- a/lib/lrama/grammar/code.rb +++ b/lib/lrama/grammar/code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "forwardable" require_relative "code/destructor_code" require_relative "code/initial_action_code" diff --git a/lib/lrama/grammar/code/destructor_code.rb b/lib/lrama/grammar/code/destructor_code.rb index 70360eb9..79401725 100644 --- a/lib/lrama/grammar/code/destructor_code.rb +++ b/lib/lrama/grammar/code/destructor_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Code diff --git a/lib/lrama/grammar/code/initial_action_code.rb b/lib/lrama/grammar/code/initial_action_code.rb index a694f193..02f2badc 100644 --- a/lib/lrama/grammar/code/initial_action_code.rb +++ b/lib/lrama/grammar/code/initial_action_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Code diff --git a/lib/lrama/grammar/code/no_reference_code.rb b/lib/lrama/grammar/code/no_reference_code.rb index 6e614cc6..ab12f32e 100644 --- a/lib/lrama/grammar/code/no_reference_code.rb +++ b/lib/lrama/grammar/code/no_reference_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Code diff --git a/lib/lrama/grammar/code/printer_code.rb b/lib/lrama/grammar/code/printer_code.rb index ffccd893..c0b8d243 100644 --- a/lib/lrama/grammar/code/printer_code.rb +++ b/lib/lrama/grammar/code/printer_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Code diff --git a/lib/lrama/grammar/code/rule_action.rb b/lib/lrama/grammar/code/rule_action.rb index 27db7044..0f96b21e 100644 --- a/lib/lrama/grammar/code/rule_action.rb +++ b/lib/lrama/grammar/code/rule_action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Code diff --git a/lib/lrama/grammar/counter.rb b/lib/lrama/grammar/counter.rb index c13f4ec3..dc91b87b 100644 --- a/lib/lrama/grammar/counter.rb +++ b/lib/lrama/grammar/counter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Counter diff --git a/lib/lrama/grammar/destructor.rb b/lib/lrama/grammar/destructor.rb index 4b7059e9..a2b6fde0 100644 --- a/lib/lrama/grammar/destructor.rb +++ b/lib/lrama/grammar/destructor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Destructor < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) diff --git a/lib/lrama/grammar/error_token.rb b/lib/lrama/grammar/error_token.rb index 8efde7df..50eaafee 100644 --- a/lib/lrama/grammar/error_token.rb +++ b/lib/lrama/grammar/error_token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class ErrorToken < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) diff --git a/lib/lrama/grammar/parameterizing_rule.rb b/lib/lrama/grammar/parameterizing_rule.rb index d371805f..ddc1a467 100644 --- a/lib/lrama/grammar/parameterizing_rule.rb +++ b/lib/lrama/grammar/parameterizing_rule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'parameterizing_rule/resolver' require_relative 'parameterizing_rule/rhs' require_relative 'parameterizing_rule/rule' diff --git a/lib/lrama/grammar/parameterizing_rule/resolver.rb b/lib/lrama/grammar/parameterizing_rule/resolver.rb index d8f3ae78..edd7c918 100644 --- a/lib/lrama/grammar/parameterizing_rule/resolver.rb +++ b/lib/lrama/grammar/parameterizing_rule/resolver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class ParameterizingRule diff --git a/lib/lrama/grammar/parameterizing_rule/rhs.rb b/lib/lrama/grammar/parameterizing_rule/rhs.rb index d4188b8f..d574841d 100644 --- a/lib/lrama/grammar/parameterizing_rule/rhs.rb +++ b/lib/lrama/grammar/parameterizing_rule/rhs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class ParameterizingRule diff --git a/lib/lrama/grammar/parameterizing_rule/rule.rb b/lib/lrama/grammar/parameterizing_rule/rule.rb index 38f0fca4..e5dd3d5b 100644 --- a/lib/lrama/grammar/parameterizing_rule/rule.rb +++ b/lib/lrama/grammar/parameterizing_rule/rule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class ParameterizingRule diff --git a/lib/lrama/grammar/percent_code.rb b/lib/lrama/grammar/percent_code.rb index 8cbc5aef..416a2d27 100644 --- a/lib/lrama/grammar/percent_code.rb +++ b/lib/lrama/grammar/percent_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class PercentCode diff --git a/lib/lrama/grammar/precedence.rb b/lib/lrama/grammar/precedence.rb index fed739b3..13cf960c 100644 --- a/lib/lrama/grammar/precedence.rb +++ b/lib/lrama/grammar/precedence.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Precedence < Struct.new(:type, :precedence, keyword_init: true) diff --git a/lib/lrama/grammar/printer.rb b/lib/lrama/grammar/printer.rb index 8984a96e..b78459e8 100644 --- a/lib/lrama/grammar/printer.rb +++ b/lib/lrama/grammar/printer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Printer < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) diff --git a/lib/lrama/grammar/reference.rb b/lib/lrama/grammar/reference.rb index c56e7673..b044516b 100644 --- a/lib/lrama/grammar/reference.rb +++ b/lib/lrama/grammar/reference.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar # type: :dollar or :at diff --git a/lib/lrama/grammar/rule.rb b/lib/lrama/grammar/rule.rb index 0e06edc8..1927d00f 100644 --- a/lib/lrama/grammar/rule.rb +++ b/lib/lrama/grammar/rule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar # _rhs holds original RHS element. Use rhs to refer to Symbol. diff --git a/lib/lrama/grammar/rule_builder.rb b/lib/lrama/grammar/rule_builder.rb index 8974ff6a..65216c57 100644 --- a/lib/lrama/grammar/rule_builder.rb +++ b/lib/lrama/grammar/rule_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class RuleBuilder diff --git a/lib/lrama/grammar/symbol.rb b/lib/lrama/grammar/symbol.rb index deb67ad9..f9dffcad 100644 --- a/lib/lrama/grammar/symbol.rb +++ b/lib/lrama/grammar/symbol.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Symbol is both of nterm and term # `number` is both for nterm and term # `token_id` is tokentype for term, internal sequence number for nterm diff --git a/lib/lrama/grammar/symbols.rb b/lib/lrama/grammar/symbols.rb index cc9b4ec5..337241d1 100644 --- a/lib/lrama/grammar/symbols.rb +++ b/lib/lrama/grammar/symbols.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require_relative "symbols/resolver" diff --git a/lib/lrama/grammar/symbols/resolver.rb b/lib/lrama/grammar/symbols/resolver.rb index 1788ed63..99bffae1 100644 --- a/lib/lrama/grammar/symbols/resolver.rb +++ b/lib/lrama/grammar/symbols/resolver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Symbols diff --git a/lib/lrama/grammar/type.rb b/lib/lrama/grammar/type.rb index 6b4b0961..65537288 100644 --- a/lib/lrama/grammar/type.rb +++ b/lib/lrama/grammar/type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Type diff --git a/lib/lrama/grammar/union.rb b/lib/lrama/grammar/union.rb index 854bffb5..5f1bee00 100644 --- a/lib/lrama/grammar/union.rb +++ b/lib/lrama/grammar/union.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Grammar class Union < Struct.new(:code, :lineno, keyword_init: true) diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index 932fcc90..c46c7358 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "strscan" require_relative "lexer/grammar_file" diff --git a/lib/lrama/lexer/grammar_file.rb b/lib/lrama/lexer/grammar_file.rb index 3d336862..45c31229 100644 --- a/lib/lrama/lexer/grammar_file.rb +++ b/lib/lrama/lexer/grammar_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class GrammarFile diff --git a/lib/lrama/lexer/location.rb b/lib/lrama/lexer/location.rb index aefce3e1..bf8f4f7e 100644 --- a/lib/lrama/lexer/location.rb +++ b/lib/lrama/lexer/location.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class Location diff --git a/lib/lrama/lexer/token.rb b/lib/lrama/lexer/token.rb index 9260798d..45a097f6 100644 --- a/lib/lrama/lexer/token.rb +++ b/lib/lrama/lexer/token.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'token/char' require_relative 'token/ident' require_relative 'token/instantiate_rule' diff --git a/lib/lrama/lexer/token/char.rb b/lib/lrama/lexer/token/char.rb index ec3560ca..9e21952c 100644 --- a/lib/lrama/lexer/token/char.rb +++ b/lib/lrama/lexer/token/char.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class Token diff --git a/lib/lrama/lexer/token/ident.rb b/lib/lrama/lexer/token/ident.rb index e576eaec..84835c00 100644 --- a/lib/lrama/lexer/token/ident.rb +++ b/lib/lrama/lexer/token/ident.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class Token diff --git a/lib/lrama/lexer/token/instantiate_rule.rb b/lib/lrama/lexer/token/instantiate_rule.rb index 1c4d1095..db7e611c 100644 --- a/lib/lrama/lexer/token/instantiate_rule.rb +++ b/lib/lrama/lexer/token/instantiate_rule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class Token diff --git a/lib/lrama/lexer/token/tag.rb b/lib/lrama/lexer/token/tag.rb index e54d7739..52dcb50c 100644 --- a/lib/lrama/lexer/token/tag.rb +++ b/lib/lrama/lexer/token/tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Lexer class Token diff --git a/lib/lrama/lexer/token/user_code.rb b/lib/lrama/lexer/token/user_code.rb index 4d487bf0..67993900 100644 --- a/lib/lrama/lexer/token/user_code.rb +++ b/lib/lrama/lexer/token/user_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "strscan" module Lrama diff --git a/lib/lrama/option_parser.rb b/lib/lrama/option_parser.rb index 1e4d448f..24ee3792 100644 --- a/lib/lrama/option_parser.rb +++ b/lib/lrama/option_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'optparse' module Lrama diff --git a/lib/lrama/options.rb b/lib/lrama/options.rb index 739ca16f..b1f122b0 100644 --- a/lib/lrama/options.rb +++ b/lib/lrama/options.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama # Command line options. class Options diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index abb99d61..a5fa7cc8 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "erb" require "forwardable" require_relative "report/duration" @@ -63,7 +65,7 @@ def render # A part of b4_token_enums def token_enums - str = "" + str = "".dup @context.yytokentype.each do |s_value, token_id, display_name| s = sprintf("%s = %d%s", s_value, token_id, token_id == yymaxutok ? "" : ",") @@ -80,7 +82,7 @@ def token_enums # b4_symbol_enum def symbol_enum - str = "" + str = "".dup last_sym_number = @context.yysymbol_kind_t.last[1] @context.yysymbol_kind_t.each do |s_value, sym_number, display_name| @@ -132,7 +134,7 @@ def int_type_for(ary) end def symbol_actions_for_printer - str = "" + str = "".dup @grammar.symbols.each do |sym| next unless sym.printer @@ -151,7 +153,7 @@ def symbol_actions_for_printer end def symbol_actions_for_destructor - str = "" + str = "".dup @grammar.symbols.each do |sym| next unless sym.destructor @@ -236,7 +238,7 @@ def after_pop_stack_function(len, comment = "") end def symbol_actions_for_error_token - str = "" + str = "".dup @grammar.symbols.each do |sym| next unless sym.error_token @@ -256,7 +258,7 @@ def symbol_actions_for_error_token # b4_user_actions def user_actions - str = "" + str = "".dup @context.states.rules.each do |rule| next unless rule.token_code @@ -343,7 +345,7 @@ def lex_param_name # b4_parse_param_use def parse_param_use(val, loc) - str = <<-STR + str = <<-STR.dup YY_USE (#{val}); YY_USE (#{loc}); STR @@ -398,7 +400,7 @@ def int_array_to_string(ary) last = ary.count - 1 s = ary.each_with_index.each_slice(10).map do |slice| - str = " " + str = " ".dup slice.each do |e, i| str << sprintf("%6d%s", e, (i == last) ? "" : ",") @@ -461,8 +463,8 @@ def template_dir end def string_array_to_string(ary) - str = "" - tmp = " " + str = "".dup + tmp = " ".dup ary.each do |s| s = s.gsub('\\', '\\\\\\\\') @@ -470,7 +472,7 @@ def string_array_to_string(ary) if (tmp + s + " \"\",").length > 75 str << tmp << "\n" - tmp = " \"#{s}\"," + tmp = " \"#{s}\",".dup else tmp << " \"#{s}\"," end diff --git a/lib/lrama/report.rb b/lib/lrama/report.rb index 496531e3..890e5f1e 100644 --- a/lib/lrama/report.rb +++ b/lib/lrama/report.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + require_relative 'report/duration' require_relative 'report/profile' diff --git a/lib/lrama/report/duration.rb b/lib/lrama/report/duration.rb index 7afe284f..fe09a0d0 100644 --- a/lib/lrama/report/duration.rb +++ b/lib/lrama/report/duration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Report module Duration diff --git a/lib/lrama/report/profile.rb b/lib/lrama/report/profile.rb index 36156800..10488cf9 100644 --- a/lib/lrama/report/profile.rb +++ b/lib/lrama/report/profile.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Report module Profile diff --git a/lib/lrama/state.rb b/lib/lrama/state.rb index 03f67ee5..c2623746 100644 --- a/lib/lrama/state.rb +++ b/lib/lrama/state.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "state/reduce" require_relative "state/reduce_reduce_conflict" require_relative "state/resolved_conflict" diff --git a/lib/lrama/state/reduce.rb b/lib/lrama/state/reduce.rb index 8ba51f45..45d509f7 100644 --- a/lib/lrama/state/reduce.rb +++ b/lib/lrama/state/reduce.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class State class Reduce diff --git a/lib/lrama/state/reduce_reduce_conflict.rb b/lib/lrama/state/reduce_reduce_conflict.rb index 0a0e4dc2..736d0837 100644 --- a/lib/lrama/state/reduce_reduce_conflict.rb +++ b/lib/lrama/state/reduce_reduce_conflict.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class State class ReduceReduceConflict < Struct.new(:symbols, :reduce1, :reduce2, keyword_init: true) diff --git a/lib/lrama/state/resolved_conflict.rb b/lib/lrama/state/resolved_conflict.rb index 02ea8921..6b67f36b 100644 --- a/lib/lrama/state/resolved_conflict.rb +++ b/lib/lrama/state/resolved_conflict.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class State # * symbol: A symbol under discussion diff --git a/lib/lrama/state/shift.rb b/lib/lrama/state/shift.rb index 2021eb61..81ef013a 100644 --- a/lib/lrama/state/shift.rb +++ b/lib/lrama/state/shift.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class State class Shift diff --git a/lib/lrama/state/shift_reduce_conflict.rb b/lib/lrama/state/shift_reduce_conflict.rb index f80bd5f3..fd668345 100644 --- a/lib/lrama/state/shift_reduce_conflict.rb +++ b/lib/lrama/state/shift_reduce_conflict.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class State class ShiftReduceConflict < Struct.new(:symbols, :shift, :reduce, keyword_init: true) diff --git a/lib/lrama/states.rb b/lib/lrama/states.rb index 04b75cca..9b18759e 100644 --- a/lib/lrama/states.rb +++ b/lib/lrama/states.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "forwardable" require_relative "report/duration" require_relative "states/item" diff --git a/lib/lrama/states/item.rb b/lib/lrama/states/item.rb index 31b74b9d..8baa16db 100644 --- a/lib/lrama/states/item.rb +++ b/lib/lrama/states/item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # TODO: Validate position is not over rule rhs require "forwardable" diff --git a/lib/lrama/states_reporter.rb b/lib/lrama/states_reporter.rb index 6f96cc6f..b56cc891 100644 --- a/lib/lrama/states_reporter.rb +++ b/lib/lrama/states_reporter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class StatesReporter include Lrama::Report::Duration diff --git a/lib/lrama/version.rb b/lib/lrama/version.rb index ef840ce4..c454222a 100644 --- a/lib/lrama/version.rb +++ b/lib/lrama/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama VERSION = "0.6.9".freeze end diff --git a/lib/lrama/warning.rb b/lib/lrama/warning.rb index 3c99791e..d7567f42 100644 --- a/lib/lrama/warning.rb +++ b/lib/lrama/warning.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lrama class Warning attr_reader :errors, :warns diff --git a/lrama.gemspec b/lrama.gemspec index 061be06b..0ca9866a 100644 --- a/lrama.gemspec +++ b/lrama.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "lib/lrama/version.rb" Gem::Specification.new do |spec| diff --git a/spec/lrama/bitmap_spec.rb b/spec/lrama/bitmap_spec.rb index 80e98171..53e7192f 100644 --- a/spec/lrama/bitmap_spec.rb +++ b/spec/lrama/bitmap_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Bitmap do describe ".from_array" do it "converts array of integer into bitmap integer" do diff --git a/spec/lrama/command_spec.rb b/spec/lrama/command_spec.rb index eace70cf..4fbe5024 100644 --- a/spec/lrama/command_spec.rb +++ b/spec/lrama/command_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "tmpdir" RSpec.describe Lrama::Command do diff --git a/spec/lrama/context_spec.rb b/spec/lrama/context_spec.rb index d4be9eb0..b5f8b792 100644 --- a/spec/lrama/context_spec.rb +++ b/spec/lrama/context_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Context do let(:out) { "" } let(:warning) { Lrama::Warning.new(out) } diff --git a/spec/lrama/counterexamples_spec.rb b/spec/lrama/counterexamples_spec.rb index 9c84c306..a210c8eb 100644 --- a/spec/lrama/counterexamples_spec.rb +++ b/spec/lrama/counterexamples_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Counterexamples do - let(:out) { "" } + let(:out) { "".dup } let(:warning) { Lrama::Warning.new(out) } describe "#compute" do diff --git a/spec/lrama/grammar/code_spec.rb b/spec/lrama/grammar/code_spec.rb index 075abd2f..b156ac0c 100644 --- a/spec/lrama/grammar/code_spec.rb +++ b/spec/lrama/grammar/code_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Grammar::Code do let(:token_class) { Lrama::Lexer::Token } let(:user_code_dollar_dollar) { token_class::UserCode.new(s_value: 'print($$);') } diff --git a/spec/lrama/grammar/rule_builder_spec.rb b/spec/lrama/grammar/rule_builder_spec.rb index a2ba733a..147b5a23 100644 --- a/spec/lrama/grammar/rule_builder_spec.rb +++ b/spec/lrama/grammar/rule_builder_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Grammar::RuleBuilder do let(:rule_counter) { Lrama::Grammar::Counter.new(1) } let(:midrule_action_counter) { Lrama::Grammar::Counter.new(1) } diff --git a/spec/lrama/grammar/symbol_spec.rb b/spec/lrama/grammar/symbol_spec.rb index 9f3fc4bf..5a619a5f 100644 --- a/spec/lrama/grammar/symbol_spec.rb +++ b/spec/lrama/grammar/symbol_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Grammar::Symbol do let(:token_class) { Lrama::Lexer::Token } diff --git a/spec/lrama/grammar/symbols/resolver_spec.rb b/spec/lrama/grammar/symbols/resolver_spec.rb index bcbcac19..02950626 100644 --- a/spec/lrama/grammar/symbols/resolver_spec.rb +++ b/spec/lrama/grammar/symbols/resolver_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Grammar::Symbols::Resolver do let(:resolver) { Lrama::Grammar::Symbols::Resolver.new } diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index 99af41f3..f10cabe2 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "open3" require "tempfile" require "tmpdir" diff --git a/spec/lrama/lexer/location_spec.rb b/spec/lrama/lexer/location_spec.rb index b7bd42f5..23cf16f9 100644 --- a/spec/lrama/lexer/location_spec.rb +++ b/spec/lrama/lexer/location_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Lexer::Location do describe "#to_s" do it "returns location information" do diff --git a/spec/lrama/lexer/token/user_code_spec.rb b/spec/lrama/lexer/token/user_code_spec.rb index 9311644f..5607c681 100644 --- a/spec/lrama/lexer/token/user_code_spec.rb +++ b/spec/lrama/lexer/token/user_code_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Lexer::Token::UserCode do describe "#references" do let(:grammar_file) { Lrama::Lexer::GrammarFile.new("test.y", "") } diff --git a/spec/lrama/lexer_spec.rb b/spec/lrama/lexer_spec.rb index 2e06fe65..71ee0d7e 100644 --- a/spec/lrama/lexer_spec.rb +++ b/spec/lrama/lexer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Lrama::Lexer do let(:token_class) { Lrama::Lexer::Token } diff --git a/spec/lrama/option_parser_spec.rb b/spec/lrama/option_parser_spec.rb index b64c8d85..ef629a72 100644 --- a/spec/lrama/option_parser_spec.rb +++ b/spec/lrama/option_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "open3" RSpec.describe Lrama::OptionParser do diff --git a/spec/lrama/output_spec.rb b/spec/lrama/output_spec.rb index 15031ce2..6fdbd196 100644 --- a/spec/lrama/output_spec.rb +++ b/spec/lrama/output_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "stringio" RSpec.describe Lrama::Output do diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 40512c87..969b5c57 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "tempfile" RSpec.describe Lrama::Parser do diff --git a/spec/lrama/states_spec.rb b/spec/lrama/states_spec.rb index e611c22c..561f52bd 100644 --- a/spec/lrama/states_spec.rb +++ b/spec/lrama/states_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe Lrama::States do - let(:out) { "" } + let(:out) { "".dup } let(:warning) { Lrama::Warning.new(out) } describe '#compute' do @@ -12,7 +14,7 @@ states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, grammar: true, states: true, itemsets: true, lookaheads: true) expect(str).to eq(<<~STR) @@ -351,7 +353,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, itemsets: true, verbose: true) expect(str).to eq(<<~STR) @@ -621,7 +623,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, itemsets: true, verbose: true) expect(str).to eq(<<~STR) @@ -922,7 +924,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, lookaheads: true) expect(str).to eq(<<~STR) @@ -993,7 +995,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, lookaheads: true, itemsets: true) expect(str).to eq(<<~STR) @@ -1085,7 +1087,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, solved: true) expect(str).to eq(<<~STR) @@ -1204,7 +1206,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, solved: true) expect(str).to eq(<<~STR) @@ -1303,7 +1305,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true, solved: true) expect(str).to eq(<<~STR) @@ -1454,7 +1456,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true) expect(str).to eq(<<~STR) @@ -1628,7 +1630,7 @@ class go to state 5 states = Lrama::States.new(grammar, warning) states.compute - str = "" + str = "".dup states.reporter.report(str, states: true) expect(str).to eq(<<~STR) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 319fa0b7..4fd80bc9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "simplecov" SimpleCov.start do