Class: OpenC3::ScriptEngine
- Defined in:
- lib/openc3/script_engines/script_engine.rb
Instance Attribute Summary collapse
-
#running_script ⇒ Object
Returns the value of attribute running_script.
Instance Method Summary collapse
- #debug(text) ⇒ Object
-
#initialize(running_script) ⇒ ScriptEngine
constructor
A new instance of ScriptEngine.
- #mnemonic_check(text, filename: nil) ⇒ Object
-
#run_line(line, lines, filename, line_no) ⇒ Object
Override this method in the subclass to implement the script engine.
- #run_text(text, filename: nil, line_no: 1, end_line_no: nil, bind_variables: false) ⇒ Object
- #syntax_check(text, filename: nil) ⇒ Object
- #tokenizer(s, special_chars = '()><+-*/=;,') ⇒ Object
Constructor Details
#initialize(running_script) ⇒ ScriptEngine
Returns a new instance of ScriptEngine.
18 19 20 |
# File 'lib/openc3/script_engines/script_engine.rb', line 18 def initialize(running_script) @running_script = running_script end |
Instance Attribute Details
#running_script ⇒ Object
Returns the value of attribute running_script.
16 17 18 |
# File 'lib/openc3/script_engines/script_engine.rb', line 16 def running_script @running_script end |
Instance Method Details
#debug(text) ⇒ Object
48 49 50 |
# File 'lib/openc3/script_engines/script_engine.rb', line 48 def debug(text) run_line(text, [text], "DEBUG", 1) end |
#mnemonic_check(text, filename: nil) ⇒ Object
57 58 59 60 |
# File 'lib/openc3/script_engines/script_engine.rb', line 57 def mnemonic_check(text, filename: nil) puts "Not Implemented" return 1 end |
#run_line(line, lines, filename, line_no) ⇒ Object
Override this method in the subclass to implement the script engine
23 24 25 26 |
# File 'lib/openc3/script_engines/script_engine.rb', line 23 def run_line(line, lines, filename, line_no) puts line return line_no + 1 end |
#run_text(text, filename: nil, line_no: 1, end_line_no: nil, bind_variables: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openc3/script_engines/script_engine.rb', line 28 def run_text(text, filename: nil, line_no: 1, end_line_no: nil, bind_variables: false) lines = text.lines loop do line = lines[line_no - 1] return if line.nil? begin next_line_no = line_no + 1 running_script.pre_line_instrumentation(filename, line_no) next_line_no = run_line(line, lines, filename, line_no) running_script.post_line_instrumentation(filename, line_no) rescue Exception => e retry if running_script.exception_instrumentation(e, filename, line_no) end line_no = next_line_no return if end_line_no and line_no > end_line_no end end |
#syntax_check(text, filename: nil) ⇒ Object
52 53 54 55 |
# File 'lib/openc3/script_engines/script_engine.rb', line 52 def syntax_check(text, filename: nil) puts "Not Implemented" return 1 end |
#tokenizer(s, special_chars = '()><+-*/=;,') ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/openc3/script_engines/script_engine.rb', line 62 def tokenizer(s, special_chars = '()><+-*/=;,') result = [] i = 0 while i < s.length # Skip whitespace if s[i].match?(/\s/) i += 1 next end # Handle quoted strings (single or double quotes) if ['"', "'"].include?(s[i]) quote_char = s[i] quote_start = i i += 1 # Find the closing quote while i < s.length if s[i] == '\\' && i + 1 < s.length # Handle escaped characters i += 2 elsif s[i] == quote_char # Found closing quote i += 1 break else i += 1 end end # Include the quotes in the token result << s[quote_start...i] next end # Handle special characters if special_chars.include?(s[i]) result << s[i] i += 1 next end # Handle regular tokens token_start = i while i < s.length && !s[i].match?(/\s/) && !special_chars.include?(s[i]) && !['"', "'"].include?(s[i]) i += 1 end if i > token_start result << s[token_start...i] end end return result end |