You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to security reasons I was attempting to update to UBI9.5, however I hit some issues. I hit an OpenSSL issue when I ran the line gem update --system 3.3.14:
OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)
To fix this I updated Ruby to 3.3.7, however I was faced with another issue in that the unit tests started to fail. Specifically the tests in ruby_lex_utils_spec.rb were failing as it appears that the class RubyLex has been refactored heavily: https://msp-greg.github.io/ruby_3_3/irb/IRB/RubyLex.html https://msp-greg.github.io/ruby_3_2/irb/RubyLex.html
I did some work to fix some of the tests by switching from using RubyLex to Prism. I have been stuck on the function each_lexed_segment as Prism for the most part has been a drop in replacement however in the implementation of this function it is a bit trickier. I am attaching the code that I have updated just to give it as an example, and it may be helpful in a future update.
It should be noted that Prism does not emit the on_sp event, so you will not be able to recreate your code with the spaces in it, thus some of the tests will need to be updated to account for this lack of spacing. ruby/prism#722
# encoding: ascii-8bit# Copyright 2022 Ball Aerospace & Technologies Corp.# All Rights Reserved.## This program is free software; you can modify and/or redistribute it# under the terms of the GNU Affero General Public License# as published by the Free Software Foundation; version 3 with# attribution addendums as found in the LICENSE.txt## 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 Affero General Public License for more details.# Modified by OpenC3, Inc.# All changes Copyright 2022, OpenC3, Inc.# All Rights Reserved## This file may also be used under the terms of a commercial license# if purchased from OpenC3, Inc.require'prism'classRubyLexUtils# Regular expression to detect blank linesBLANK_LINE_REGEX=/^\s*$/# Regular expression to detect lines containing only 'else'LONELY_ELSE_REGEX=/^\s*else\s*$/KEY_KEYWORDS=['class'.freeze,'module'.freeze,'def'.freeze,'undef'.freeze,'begin'.freeze,'rescue'.freeze,'ensure'.freeze,'end'.freeze,'if'.freeze,'unless'.freeze,'then'.freeze,'elsif'.freeze,'else'.freeze,'case'.freeze,'when'.freeze,'while'.freeze,'until'.freeze,'for'.freeze,'break'.freeze,'next'.freeze,'redo'.freeze,'retry'.freeze,'in'.freeze,'do'.freeze,'return'.freeze,'alias'.freeze]# @param text [String]# @return [Boolean] Whether the text contains the 'begin' keyworddefcontains_begin?(text)lex=Prism.lex(text)tokens=lex.valuetokens.eachdo |token|
token_object=token[0]iftoken_object.type == :KEYWORD_BEGINreturntrueendendreturnfalseend# @param text [String]# @return [Boolean] Whether the text contains the 'end' keyworddefcontains_end?(text)lex=Prism.lex(text)tokens=lex.valuetokens.eachdo |token|
token_object=token[0]iftoken_object.type == :KEYWORD_ENDreturntrueendendreturnfalseend# @param text [String]# @return [Boolean] Whether the text contains a Ruby keyworddefcontains_keyword?(text)lex=Prism.lex(text)tokens=lex.valuetokens.eachdo |token|
token_object=token[0]state_bits=token[1]iftoken_object.type.start_with?("KEYWORD")ifKEY_KEYWORDS.include?(token_object.value)returntrueendelsiftoken_object.type == :BRACE_LEFTandstate_bits != (Ripper::EXPR_BEG | Ripper::EXPR_LABEL)returntrueendendreturnfalseend# @param text [String]# @return [Boolean] Whether the text contains a keyword which starts a block.# i.e. 'do', '{', or 'begin'defcontains_block_beginning?(text)lex=Prism.lex(text)tokens=lex.valuetokens.eachdo |token|
token_object=token[0]iftoken_object.type == :KEYWORD_BEGIN || token_object.type == :KEYWORD_DO || token_object.type == :BRACE_LEFTreturntrueendendreturnfalseenddefcontinue_block?(text)lex=Prism.lex(text)tokens=lex.valueindex=tokens.length - 1whileindex > 0token_object=tokens[index][0]returntrueiftoken_object.type == :KEYWORD_DOindex -= 1endreturnfalseend# @param text [String]# @param progress_dialog [OpenC3::ProgressDialog] If this is set, the overall# progress will be set as the processing progresses# @return [String] The text with all comments removeddefremove_comments(text,progress_dialog=nil)lex=Prism.lex(text)tokens=lex.valuecomments_removed=""token_count=0progress=0.0tokens.eachdo |token|
token_object=token[0]token_count += 1iftoken_object.type != :COMMENTcomments_removed << token_object.valueelsenewline_count=token_object.value.count("\n")comments_removed << ("\n" * newline_count)endifprogress_dialogandtoken_count % 10000 == 0progress += 0.01progress=0.0ifprogress >= 0.99progress_dialog.set_overall_progress(progress)endendreturncomments_removedend
The text was updated successfully, but these errors were encountered:
Thanks @stephen-ritter! We've been specifically holding off on upgrading Ruby due to the changes with IRB. Prism is the right answer and we recently updated the python parsing in script_instrumentor.py which should be very similar to how the new Prism code works.
We currently have an open ticket #1579 to address the Ruby upgrade. This isn't a high priority for us but should be implemented by the end of Q2 2025.
Due to security reasons I was attempting to update to UBI9.5, however I hit some issues. I hit an OpenSSL issue when I ran the line
gem update --system 3.3.14
:To fix this I updated Ruby to 3.3.7, however I was faced with another issue in that the unit tests started to fail. Specifically the tests in
ruby_lex_utils_spec.rb
were failing as it appears that the classRubyLex
has been refactored heavily:https://msp-greg.github.io/ruby_3_3/irb/IRB/RubyLex.html
https://msp-greg.github.io/ruby_3_2/irb/RubyLex.html
I did some work to fix some of the tests by switching from using
RubyLex
toPrism
. I have been stuck on the functioneach_lexed_segment
asPrism
for the most part has been a drop in replacement however in the implementation of this function it is a bit trickier. I am attaching the code that I have updated just to give it as an example, and it may be helpful in a future update.It should be noted that
Prism
does not emit theon_sp
event, so you will not be able to recreate your code with the spaces in it, thus some of the tests will need to be updated to account for this lack of spacing.ruby/prism#722
The text was updated successfully, but these errors were encountered: