Class: Kuroko2::Workflow::ShellScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/autoload/kuroko2/workflow/shell_scanner.rb

Constant Summary collapse

STRING_LITERAL =
/("([^"]|\")*"|'([^']|\')*')/

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ ShellScanner

Returns a new instance of ShellScanner.



8
9
10
# File 'lib/autoload/kuroko2/workflow/shell_scanner.rb', line 8

def initialize(text)
  @text = text
end

Instance Method Details

#strip_commentObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/autoload/kuroko2/workflow/shell_scanner.rb', line 12

def strip_comment
  return @text if @text.nil?

  result = ''
  while scanner.rest?
    break if scanner.peek(1) == '#'

    token = scanner.scan(/[^'"#]+/) || scanner.scan(STRING_LITERAL) || scanner.scan(/[^#]+/)
    break if token.nil?

    result << token
  end
  result
end