Module: ANTLR3::Util

Included in:
AST::Wizard, Main::Main
Defined in:
lib/antlr3/util.rb

Class Method Summary collapse

Class Method Details

.parse_version(version_string) ⇒ Object



17
18
19
20
21
# File 'lib/antlr3/util.rb', line 17

def parse_version( version_string )
  version_string.split( '.' ).map! do | segment |
    segment.to_i
  end.freeze
end

.silence_warningsObject



32
33
34
35
36
37
# File 'lib/antlr3/util.rb', line 32

def silence_warnings
  verbosity, $VERBOSE = $VERBOSE, nil
  return yield
ensure
  $VERBOSE = verbosity
end

.snake_case(str) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/antlr3/util.rb', line 9

def snake_case( str )
  str = str.to_s.gsub( /([A-Z]+)([A-Z][a-z])/,'\1_\2' )
  str.gsub!( /([a-z\d])([A-Z])/,'\1_\2' )
  str.tr!( "-", "_" )
  str.downcase!
  str
end

.tidy(here_doc, flow = false) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/antlr3/util.rb', line 23

def tidy( here_doc, flow = false )
  here_doc.gsub!( /^ *\| ?/, '' )
  if flow
    here_doc.strip!
    here_doc.gsub!( /\s+/, ' ' )
  end
  return here_doc
end