class AdLint::Cpp::Initial
Public Instance Methods
next_token()
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 307 def next_token # NOTE: An escaped newline may appear at the line above a preprocessing # directive line. loop do unless discard_heading_comments || scan_escaped_newline(@lexer.content) break end end case when @lexer.content.check(/[ \t]*#/) case when tok = tokenize_if_directive(@lexer.content) @lexer.transit(InIfDirective.new(@lexer)) when tok = tokenize_ifdef_directive(@lexer.content) @lexer.transit(InIfdefDirective.new(@lexer)) when tok = tokenize_ifndef_directive(@lexer.content) @lexer.transit(InIfndefDirective.new(@lexer)) when tok = tokenize_elif_directive(@lexer.content) @lexer.transit(InElifDirective.new(@lexer)) when tok = tokenize_else_directive(@lexer.content) @lexer.transit(InElseDirective.new(@lexer)) when tok = tokenize_endif_directive(@lexer.content) @lexer.transit(InEndifDirective.new(@lexer)) when tok = tokenize_include_directive(@lexer.content) @lexer.transit(InIncludeDirective.new(@lexer)) when tok = tokenize_include_next_directive(@lexer.content) @lexer.transit(InIncludeNextDirective.new(@lexer)) when tok = tokenize_define_directive(@lexer.content) @lexer.transit(InDefineDirective.new(@lexer)) when tok = tokenize_undef_directive(@lexer.content) @lexer.transit(InUndefDirective.new(@lexer)) when tok = tokenize_line_directive(@lexer.content) @lexer.transit(InLineDirective.new(@lexer)) when tok = tokenize_error_directive(@lexer.content) @lexer.transit(InErrorDirective.new(@lexer)) when tok = tokenize_pragma_directive(@lexer.content) @lexer.transit(InPragmaDirective.new(@lexer)) when tok = tokenize_asm_directive(@lexer.content) @lexer.transit(InAsmDirective.new(@lexer)) when tok = tokenize_endasm_directive(@lexer.content) @lexer.transit(InEndasmDirective.new(@lexer)) else tok = tokenize_null_directive(@lexer.content) || tokenize_unknown_directive(@lexer.content) end else tok = tokenize_text_line(@lexer.content) end tok end
Private Instance Methods
tokenize_asm_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 466 def tokenize_asm_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*asm\b/) return Token.new(:ASM, val, loc) end nil end
tokenize_define_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 426 def tokenize_define_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*define\b/) return Token.new(:DEFINE, val, loc) end nil end
tokenize_elif_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 385 def tokenize_elif_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*elif\b/) return Token.new(:ELIF, val, loc) end nil end
tokenize_else_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 393 def tokenize_else_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*else\b/) return Token.new(:ELSE, val, loc) end nil end
tokenize_endasm_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 474 def tokenize_endasm_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*endasm\b/) return Token.new(:ENDASM, val, loc) end nil end
tokenize_endif_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 401 def tokenize_endif_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*endif\b/) return Token.new(:ENDIF, val, loc) end nil end
tokenize_error_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 450 def tokenize_error_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*error\b/) return Token.new(:ERROR, val, loc) end nil end
tokenize_if_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 361 def tokenize_if_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*if\b/) return Token.new(:IF, val, loc) end nil end
tokenize_ifdef_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 369 def tokenize_ifdef_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*ifdef\b/) return Token.new(:IFDEF, val, loc) end nil end
tokenize_ifndef_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 377 def tokenize_ifndef_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*ifndef\b/) return Token.new(:IFNDEF, val, loc) end nil end
tokenize_include_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 409 def tokenize_include_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*include\b/) return Token.new(:INCLUDE, val, loc) end nil end
tokenize_include_next_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 417 def tokenize_include_next_directive(cont) # NOTE: #include_next directive is a GCC extension. loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*include_next\b/) return Token.new(:INCLUDE_NEXT, val, loc) end nil end
tokenize_line_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 442 def tokenize_line_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*line\b/) return Token.new(:LINE, val, loc) end nil end
tokenize_null_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 482 def tokenize_null_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]\n/) return Token.new(:NULL_DIRECTIVE, val, loc) end nil end
tokenize_pragma_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 458 def tokenize_pragma_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*pragma\b/) return Token.new(:PRAGMA, val, loc) end nil end
tokenize_text_line(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 507 def tokenize_text_line(cont) loc = cont.location val = "" until cont.empty? if tok = cont.scan(/.*?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i) val += tok end if tok = cont.scan(/\n/) val += tok break end next if scan_escaped_newline(cont) case when cont.check(/\/\*/) discard_heading_comments when cont.check(/\/\//) discard_heading_comments when cont.check(/L?"/i) string_literal = Language::C.scan_string_literal(cont) val += string_literal when cont.check(/L?'/i) char_constant = Language::C.scan_char_constant(cont) val += char_constant end end val.empty? ? nil : Token.new(:TEXT_LINE, val, loc) end
tokenize_undef_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 434 def tokenize_undef_directive(cont) loc = cont.location if val = cont.scan(/[ \t]*#[ \t]*undef\b/) return Token.new(:UNDEF, val, loc) end nil end
tokenize_unknown_directive(cont)
click to toggle source
# File lib/adlint/cpp/lexer.rb, line 490 def tokenize_unknown_directive(cont) loc = cont.location val = cont.scan(/[ \t]*#/) until cont.empty? next if discard_heading_comments || scan_escaped_newline(cont) case when str = cont.scan(/.+?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i) val += str when str = cont.scan(/\n/) val += str break end end Token.new(:UNKNOWN_DIRECTIVE, val, loc) end