module AdLint::Cc1::Scanner

DESCRIPTION

Utility module for scanning the C source code.

Constants

FLOATING1_RE
FLOATING2_RE
KEYWORDS_RE
PUNCTUATORS_RE

Public Instance Methods

scan_char_constant(cont) click to toggle source

DESCRIPTION

Scans C character constant.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C character constant string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 187
def scan_char_constant(cont)
  unless scanned = cont.scan(/L?'/i)
    return nil
  end

  until cont.empty?
    if str = cont.scan(/.*?(?=\\|')/m)
      scanned << str
    end
    next if cont.scan(/\\[ \t]*\n/)

    case
    when cont.check(/\\/)
      scanned << cont.eat!(2)
    when quote = cont.scan(/'/)
      scanned << quote
      break
    end
  end

  scanned
end
scan_floating_constant(cont) click to toggle source

DESCRIPTION

Scans C floating constant.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C floating constant string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 174
def scan_floating_constant(cont)
  cont.scan(FLOATING1_RE) || cont.scan(FLOATING2_RE)
end
scan_identifier(cont) click to toggle source

DESCRIPTION

Scans C identifier.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C identifier string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 108
def scan_identifier(cont)
  cont.scan(/[a-z_][a-z_0-9]*\b/i)
end
scan_integer_constant(cont) click to toggle source

DESCRIPTION

Scans C integer constant.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C integer constant string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 157
def scan_integer_constant(cont)
  cont.scan(/(?:0x[0-9a-f]*|0b[01]*|[0-9]+)[UL]*/i)
end
scan_keyword(cont) click to toggle source

DESCRIPTION

Scans C keyword.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C keyword string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 125
def scan_keyword(cont)
  cont.scan(KEYWORDS_RE)
end
scan_null_constant(cont) click to toggle source

DESCRIPTION

Scans C NULL constant.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C NULL constant string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 250
def scan_null_constant(cont)
  cont.scan(/NULL\b/)
end
scan_punctuator(cont) click to toggle source

DESCRIPTION

Scans C punctuator.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C punctuator string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 144
def scan_punctuator(cont)
  cont.scan(PUNCTUATORS_RE)
end
scan_string_literal(cont) click to toggle source

DESCRIPTION

Scans C string literal.

PARAMETER

cont

StringContent – Scanning source.

RETURN VALUE

String – Returns C string literal string if found at head of the content.

# File lib/adlint/cc1/scanner.rb, line 219
def scan_string_literal(cont)
  unless scanned = cont.scan(/L?"/i)
    return nil
  end

  until cont.empty?
    if str = cont.scan(/.*?(?=\\|")/m)
      scanned << str
    end
    next if cont.scan(/\\[ \t]*\n/)

    case
    when cont.check(/\\/)
      scanned << cont.eat!(2)
    when quote = cont.scan(/"/)
      scanned << quote
      break
    end
  end

  scanned
end