class Syntax::AnsiC

Constants

ANSIC_ESCAPE
ANSIC_KEYWORDS
ANSIC_PREDEFINED_CONSTANTS
ANSIC_PREDEFINED_TYPES

Public Class Methods

add_type(name) click to toggle source
# File lib/syntax/lang/ansic.rb, line 7
def self.add_type(name)
  ANSIC_PREDEFINED_TYPES << name
end

Public Instance Methods

step() click to toggle source
# File lib/syntax/lang/ansic.rb, line 25
def step
  case
  when scan(/\s+/)
    start_group :normal, matched
  when match = scan(/#\s*(\w*)/)
    match << scan_until(/\n/)
    start_group :preprocessor, match
  when scan(/ L?' (?: [^\\n\] | \ #{ANSIC_ESCAPE} )? '? /ox)
    start_group :char, matched
  when scan(/0[xX][0-9A-Fa-f]+/)
    start_group :hex, matched
  when scan(/(?:0[0-7]+)(?![89.eEfF])/)
    start_group :oct, matched
  when scan(/(?:\d+)(?![.eEfF])/)
    start_group :integer, matched
  when scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
    start_group :float, matched
  when scan(/"(?:[^"\]|\.)*"/)
    start_group :string, matched
  when scan( %r{ ('(?: . | [\t\b\n] )') }x )
    start_group :char, matched
  when scan(/[a-z_][a-z_\d]+/)
    if ANSIC_KEYWORDS.include?( matched )
      start_group :keyword, matched
    elsif ANSIC_PREDEFINED_TYPES.include?( matched )
      start_group :predefined_types, matched
    else
      start_group :ident, matched
    end
  when scan(%r! // [^\n\]* (?: \. [^\n\]* )* | /\* (?: .*? \*/ | .* ) !mx)
    start_group :comment, matched
  else
    start_group :other, scan(/./x)
  end
end