diff --git a/lib/coderay/scanners/c.rb b/lib/coderay/scanners/c.rb index fb2f30db..a0ac0b7c 100644 --- a/lib/coderay/scanners/c.rb +++ b/lib/coderay/scanners/c.rb @@ -73,6 +73,15 @@ def scan_tokens encoder, options end encoder.text_token match, :operator + elsif match = scan(/L?"/) + encoder.begin_group :string + if match[0] == ?L + encoder.text_token 'L', :modifier + match = '"' + end + encoder.text_token match, :delimiter + state = :string + elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x) kind = IDENT_KIND[match] if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/) @@ -89,15 +98,6 @@ def scan_tokens encoder, options end encoder.text_token match, kind - elsif match = scan(/L?"/) - encoder.begin_group :string - if match[0] == ?L - encoder.text_token 'L', :modifier - match = '"' - end - encoder.text_token match, :delimiter - state = :string - elsif match = scan(/ \# \s* if \s* 0 /x) match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos? encoder.text_token match, :comment diff --git a/lib/coderay/scanners/cpp.rb b/lib/coderay/scanners/cpp.rb index cd4d0941..15d1ffa0 100644 --- a/lib/coderay/scanners/cpp.rb +++ b/lib/coderay/scanners/cpp.rb @@ -89,6 +89,15 @@ def scan_tokens encoder, options end encoder.text_token match, :operator + elsif match = scan(/L?"/) + encoder.begin_group :string + if match[0] == ?L + encoder.text_token 'L', :modifier + match = '"' + end + state = :string + encoder.text_token match, :delimiter + elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x) kind = IDENT_KIND[match] if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/) @@ -110,15 +119,6 @@ def scan_tokens encoder, options elsif match = scan(/\$/) encoder.text_token match, :ident - elsif match = scan(/L?"/) - encoder.begin_group :string - if match[0] == ?L - encoder.text_token match, 'L', :modifier - match = '"' - end - state = :string - encoder.text_token match, :delimiter - elsif match = scan(/#[ \t]*(\w*)/) encoder.text_token match, :preprocessor in_preproc_line = true