Class: Rouge::Lexers::PHP

Inherits:
TemplateLexer show all
Defined in:
lib/rouge/lexers/php.rb,
lib/rouge/lexers/php/keywords.rb

Direct Known Subclasses

Hack

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Instance Attribute Summary

Attributes inherited from Rouge::Lexer

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TemplateLexer

#parent

Methods inherited from RegexLexer

append, #delegate, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, state, #state, #state?, state_definitions, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, #as_bool, #as_lexer, #as_list, #as_string, #as_token, #bool_option, continue_lex, #continue_lex, debug_enabled?, demo, demo_file, desc, detectable?, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #lex, lex, #lexer_option, #list_option, lookup_fancy, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, tag, #tag, title, #token_option, #with

Methods included from Token::Tokens

token

Constructor Details

#initializePHP

Returns a new instance of PHP.



21
22
23
24
25
26
27
28
29
# File 'lib/rouge/lexers/php.rb', line 21

def initialize(*)
  super

  # if truthy, the lexer starts highlighting with php code
  # (no <?php required)
  @start_inline = bool_option(:start_inline) { :guess }
  @funcnamehighlighting = bool_option(:funcnamehighlighting) { true }
  @disabledmodules = list_option(:disabledmodules)
end

Class Method Details

.builtinsObject



51
52
53
54
# File 'lib/rouge/lexers/php.rb', line 51

def self.builtins
  Kernel::load File.join(Lexers::BASE_DIR, 'php/keywords.rb')
  builtins
end

.detect?(text) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/rouge/lexers/php.rb', line 31

def self.detect?(text)
  return true if text.shebang?('php')
  return false if /^<\?hh/ =~ text
  return true if /^<\?php/ =~ text
end

.keywordsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rouge/lexers/php.rb', line 37

def self.keywords
  @keywords ||= Set.new %w(
    old_function cfunction
    __class__ __dir__ __file__ __function__ __halt_compiler __line__
    __method__ __namespace__ __trait__ abstract and array as break case
    catch clone continue declare default die do echo else elseif empty
    enddeclare endfor endforeach endif endswitch endwhile eval exit
    extends final finally fn for foreach global goto if implements
    include include_once instanceof insteadof isset list match new or
    parent print private protected public readonly require require_once
    return self static switch throw try unset var while xor yield
  )
end

Instance Method Details

#builtinsObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/rouge/lexers/php.rb', line 56

def builtins
  return [] unless @funcnamehighlighting

  @builtins ||= Set.new.tap do |builtins|
    self.class.builtins.each do |mod, fns|
      next if @disabledmodules.include? mod
      builtins.merge(fns)
    end
  end
end