Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check syntax before instrumenting & remove require_utility #1082

Merged
3 commits merged into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions autohotkey/procedures/collect.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_utility 'collect_util.rb'
require_utility 'clear_util.rb'
load_utility 'collect_util.rb'
load_utility 'clear_util.rb'

number = ask("Enter a number.")
raise "Bad return" unless number.is_a? Numeric
Expand Down
2 changes: 1 addition & 1 deletion autohotkey/procedures/collect_util.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_utility 'clear_util.rb'
load_utility 'clear_util.rb'

def collect (type, duration, call_clear = false)
# Get the current collects telemetry point
Expand Down
2 changes: 1 addition & 1 deletion autohotkey/procedures/script_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_utility 'clear_util'
load_utility 'clear_util'

display("INST ADCS")
wait 2
Expand Down
2 changes: 1 addition & 1 deletion bin/cstol_converter
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def parse_line(full_line, loc_out_file, wait_check_flag=false)
# Process procedures with arguments as functions
else
# Add the statement to require the function
str = str + "require_utility(\"" + words[1].downcase + ".rb\")\n"
str = str + "load_utility(\"" + words[1].downcase + ".rb\")\n"
numSpaces.times {str = str + " "}

# Split the list of arguments on commas
Expand Down
16 changes: 8 additions & 8 deletions demo/procedures/cosmos_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@
get_cmd_param_list("INST", "COLLECT", "DURATION")

# get_cmd_hazardous
hazardous, hazardous_description = get_cmd_hazardous("INST", "COLLECT", "TYPE" => "SPECIAL")
puts "#{hazardous}:#{hazardous_description}"
hazardous, hazardous_description = get_cmd_hazardous("INST", "COLLECT", "TYPE" => "NORMAL")
puts "#{hazardous}:#{hazardous_description}"
hazardous, hazardous_description = get_cmd_hazardous("INST", "ABORT")
puts "#{hazardous}:#{hazardous_description}"
hazardous, hazardous_description = get_cmd_hazardous("INST", "CLEAR")
puts "#{hazardous}:#{hazardous_description}"
hazardous = get_cmd_hazardous("INST", "COLLECT", "TYPE" => "SPECIAL")
puts hazardous
hazardous = get_cmd_hazardous("INST", "COLLECT", "TYPE" => "NORMAL")
puts hazardous
hazardous = get_cmd_hazardous("INST", "ABORT")
puts hazardous
hazardous = get_cmd_hazardous("INST", "CLEAR")
puts hazardous

# get_cmd_hazardous should fail
get_cmd_hazardous()
Expand Down
4 changes: 2 additions & 2 deletions lib/cosmos/tools/script_runner/script_runner_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,12 @@ def self.instrument_script_implementation(ruby_lex_utils,
"ScriptRunnerFrame.instance.pre_line_instrumentation('#{filename}', #{line_no}); "

# Add the actual line
instrumented_line << "__return_val = "
instrumented_line << "__return_val = begin; "
instrumented_line << segment
instrumented_line.chomp!

# Add postline instrumentation
instrumented_line << "; ScriptRunnerFrame.instance.post_line_instrumentation('#{filename}', #{line_no}); "
instrumented_line << " end; ScriptRunnerFrame.instance.post_line_instrumentation('#{filename}', #{line_no}); "

# Complete begin block to catch exceptions
unless inside_begin
Expand Down
4 changes: 2 additions & 2 deletions lib/cosmos/tools/test_runner/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def require_utilities
ScriptRunnerFrame.instance = @script_runner_frame
build = false
@utilities.each do |utility|
if require_utility(utility)
if load_utility(utility)
build = true
end
end
Expand Down Expand Up @@ -999,7 +999,7 @@ def process_config(filename)
when 'LOAD_UTILITY', 'REQUIRE_UTILITY'
parser.verify_num_parameters(1, 1, "LOAD_UTILITY <filename>")
begin
require_utility params[0]
load_utility(params[0])
@utilities << params[0]
rescue Exception => err
require_errors << "<b>#{params[0]}</b>:\n#{err.formatted}\n"
Expand Down
64 changes: 34 additions & 30 deletions lib/cosmos/utilities/ruby_lex_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,45 @@ def reinitialize
@exception_on_syntax_error = true
@prompt = nil
end

# Monkey patch to keep this from looping forever if the string never is closed with a right brace
def identify_string_dvar
begin
getc

# Monkey patch to fix performance issue caused by call to reverse
def get_readed
if idx = @readed.rindex("\n")
@base_char_no = @readed.size - (idx + 1)
else
@base_char_no += @readed.size
end
reserve_continue = @continue
reserve_ltype = @ltype
reserve_indent = @indent
reserve_indent_stack = @indent_stack
reserve_state = @lex_state
reserve_quoted = @quoted

readed = @readed.join("")
@readed = []
readed
end
@ltype = nil
@quoted = nil
@indent = 0
@indent_stack = []
@lex_state = EXPR_BEG

# Monkey patch to fix performance issue caused by call to reverse
def ungetc(c = nil)
if @here_readed.empty?
c2 = @readed.pop
else
c2 = @here_readed.pop
end
c = c2 unless c
@rests.unshift c #c =
@seek -= 1
if c == "\n"
@line_no -= 1
if idx = @readed.rindex("\n")
@char_no = idx + 1
else
@char_no = @base_char_no + @readed.size
loop do
@continue = false
prompt
tk = token
break if tk.nil? # This is the patch
if @ltype or @continue or @indent >= 0
next
end
break if tk.kind_of?(TkRBRACE)
end
else
@char_no -= 1
ensure
@continue = reserve_continue
@ltype = reserve_ltype
@indent = reserve_indent
@indent_stack = reserve_indent_stack
@lex_state = reserve_state
@quoted = reserve_quoted
end
end
end

end
$VERBOSE = old_verbose

Expand Down