Module: AdLint::Cc1::Scanner
Overview
DESCRIPTION
Utility module for scanning the C source code.
Constant Summary
Constants included from ScannerConstants
AdLint::Cc1::ScannerConstants::KEYWORDS, AdLint::Cc1::ScannerConstants::KEYWORD_VALUES, AdLint::Cc1::ScannerConstants::PUNCTUATORS
Instance Method Summary collapse
-
#scan_char_constant(cont) ⇒ Object
DESCRIPTION Scans C character constant.
-
#scan_floating_constant(cont) ⇒ Object
DESCRIPTION Scans C floating constant.
-
#scan_identifier(cont) ⇒ Object
DESCRIPTION Scans C identifier.
-
#scan_integer_constant(cont) ⇒ Object
DESCRIPTION Scans C integer constant.
-
#scan_keyword(cont) ⇒ Object
DESCRIPTION Scans C keyword.
-
#scan_null_constant(cont) ⇒ Object
DESCRIPTION Scans C NULL constant.
-
#scan_punctuator(cont) ⇒ Object
DESCRIPTION Scans C punctuator.
-
#scan_string_literal(cont) ⇒ Object
DESCRIPTION Scans C string literal.
Instance Method Details
#scan_char_constant(cont) ⇒ Object
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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# 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) ⇒ Object
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.
174 175 176 |
# 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) ⇒ Object
DESCRIPTION
Scans C identifier.
PARAMETER
- cont
-
StringContent – Scanning source.
RETURN VALUE
String – Returns C identifier string if found at head of the content.
108 109 110 |
# 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) ⇒ Object
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.
157 158 159 |
# 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) ⇒ Object
DESCRIPTION
Scans C keyword.
PARAMETER
- cont
-
StringContent – Scanning source.
RETURN VALUE
String – Returns C keyword string if found at head of the content.
125 126 127 |
# File 'lib/adlint/cc1/scanner.rb', line 125 def scan_keyword(cont) cont.scan(KEYWORDS_RE) end |
#scan_null_constant(cont) ⇒ Object
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.
250 251 252 |
# File 'lib/adlint/cc1/scanner.rb', line 250 def scan_null_constant(cont) cont.scan(/NULL\b/) end |
#scan_punctuator(cont) ⇒ Object
DESCRIPTION
Scans C punctuator.
PARAMETER
- cont
-
StringContent – Scanning source.
RETURN VALUE
String – Returns C punctuator string if found at head of the content.
144 145 146 |
# File 'lib/adlint/cc1/scanner.rb', line 144 def scan_punctuator(cont) cont.scan(PUNCTUATORS_RE) end |
#scan_string_literal(cont) ⇒ Object
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.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# 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 |