BVB Source Codes

rouge Show php.rb Source code

Return Download rouge: download php.rb Source code - Download rouge Source code - Type:.rb
  1. # -*- coding: utf-8 -*- #
  2.  
  3. module Rouge
  4.   module Lexers
  5.     class PHP < TemplateLexer
  6.       title "PHP"
  7.       desc "The PHP scripting language (php.net)"
  8.       tag 'php'
  9.       aliases 'php', 'php3', 'php4', 'php5'
  10.       filenames '*.php', '*.php[345t]','*.phtml',
  11.                 # Support Drupal file extensions, see:
  12.                 # https://github.com/gitlabhq/gitlabhq/issues/8900
  13.                 '*.module', '*.inc', '*.profile', '*.install', '*.test'
  14.       mimetypes 'text/x-php'
  15.  
  16.       default_options :parent => 'html'
  17.  
  18.       def initialize(opts={})
  19.         # if truthy, the lexer starts highlighting with php code
  20.         # (no <?php required)
  21.         @start_inline = opts.delete(:start_inline)
  22.         @funcnamehighlighting = opts.delete(:funcnamehighlighting) { true }
  23.         @disabledmodules = opts.delete(:disabledmodules) { [] }
  24.  
  25.         super(opts)
  26.       end
  27.  
  28.       def self.builtins
  29.         load Pathname.new(__FILE__).dirname.join('php/builtins.rb')
  30.         self.builtins
  31.       end
  32.  
  33.       def builtins
  34.         return [] unless @funcnamehighlighting
  35.  
  36.         @builtins ||= Set.new.tap do |builtins|
  37.           self.class.builtins.each do |mod, fns|
  38.             next if @disabledmodules.include? mod
  39.             builtins.merge(fns)
  40.           end
  41.         end
  42.       end
  43.  
  44.       def start_inline?
  45.         !!@start_inline
  46.       end
  47.  
  48.       start do
  49.         push :php if start_inline?
  50.       end
  51.  
  52.       def self.keywords
  53.         @keywords ||= Set.new %w(
  54.           and E_PARSE old_function E_ERROR or as E_WARNING parent eval
  55.           PHP_OS break exit case extends PHP_VERSION cfunction FALSE
  56.           print for require continue foreach require_once declare return
  57.           default static do switch die stdClass echo else TRUE elseif
  58.           var empty if xor enddeclare include virtual endfor include_once
  59.           while endforeach global __FILE__ endif list __LINE__ endswitch
  60.           new __sleep endwhile not array __wakeup E_ALL NULL final
  61.           php_user_filter interface implements public private protected
  62.           abstract clone try catch throw this use namespace yield
  63.         )
  64.       end
  65.  
  66.       def self.analyze_text(text)
  67.         return 1 if text.shebang?('php')
  68.         return 0.3 if /<\?(?!xml)/ =~ text
  69.         0
  70.       end
  71.  
  72.       state :root do
  73.         rule /<\?(php|=)?/, Comment::Preproc, :php
  74.         rule(/.*?(?=<\?)|.*/m) { delegate parent }
  75.       end
  76.  
  77.       state :php do
  78.         rule /\?>/, Comment::Preproc, :pop!
  79.         # heredocs
  80.         rule /<<<('?)([a-z_]\w*)\1\n.*?\n\2;?\n/im, Str::Heredoc
  81.        rule /\s+/, Text
  82.        rule /#.*?\n/, Comment::Single
  83.        rule %r(//.*?\n), Comment::Single
  84.        # empty comment, otherwise seen as the start of a docstring
  85.        rule %r(/\*\*/), Comment::Multiline
  86.        rule %r(/\*\*.*?\*/)m, Str::Doc
  87.        rule %r(/\*.*?\*/)m, Comment::Multiline
  88.        rule /(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)/ do
  89.          groups Operator, Text, Name::Attribute
  90.        end
  91.  
  92.        rule /[~!%^&*+=\|:.<>\/?@-]+/, Operator
  93.        rule /[\[\]{}();,]/, Punctuation
  94.        rule /class\b/, Keyword, :classname
  95.        # anonymous functions
  96.        rule /(function)(\s*)(?=\()/ do
  97.          groups Keyword, Text
  98.        end
  99.  
  100.        # named functions
  101.        rule /(function)(\s+)(&?)(\s*)/ do
  102.          groups Keyword, Text, Operator, Text
  103.          push :funcname
  104.        end
  105.  
  106.        rule /(const)(\s+)([a-zA-Z_]\w*)/i do
  107.          groups Keyword, Text, Name::Constant
  108.        end
  109.  
  110.        rule /(true|false|null)\b/, Keyword::Constant
  111.        rule /\$\{\$+[a-z_]\w*\}/i, Name::Variable
  112.        rule /\$+[a-z_]\w*/i, Name::Variable
  113.  
  114.        # may be intercepted for builtin highlighting
  115.        rule /[\\a-z_][\\\w]*/i do |m|
  116.          name = m[0]
  117.  
  118.          if self.class.keywords.include? name
  119.            token Keyword
  120.          elsif self.builtins.include? name
  121.            token Name::Builtin
  122.          else
  123.            token Name::Other
  124.          end
  125.        end
  126.  
  127.        rule /(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i, Num::Float
  128.        rule /\d+e[+-]?\d+/i, Num::Float
  129.        rule /0[0-7]+/, Num::Oct
  130.        rule /0x[a-f0-9]+/i, Num::Hex
  131.        rule /\d+/, Num::Integer
  132.        rule /'([^'\\]*(?:\\.[^'\\]*)*)'/, Str::Single
  133.        rule /`([^`\\]*(?:\\.[^`\\]*)*)`/, Str::Backtick
  134.        rule /"/, Str::Double, :string
  135.      end
  136.  
  137.      state :classname do
  138.        rule /\s+/, Text
  139.        rule /[a-z_][\\\w]*/i, Name::Class, :pop!
  140.      end
  141.  
  142.      state :funcname do
  143.        rule /[a-z_]\w*/i, Name::Function, :pop!
  144.      end
  145.  
  146.      state :string do
  147.        rule /"/, Str::Double, :pop!
  148.        rule /[^\\{$"]+/, Str::Double
  149.        rule /\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})/,
  150.          Str::Escape
  151.        rule /\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?/, Name::Variable
  152.  
  153.        rule /\{\$\{/, Str::Interpol, :interp_double
  154.        rule /\{(?=\$)/, Str::Interpol, :interp_single
  155.        rule /(\{)(\S+)(\})/ do
  156.          groups Str::Interpol, Name::Variable, Str::Interpol
  157.        end
  158.  
  159.        rule /[${\\]+/, Str::Double
  160.      end
  161.  
  162.      state :interp_double do
  163.        rule /\}\}/, Str::Interpol, :pop!
  164.        mixin :php
  165.      end
  166.  
  167.      state :interp_single do
  168.        rule /\}/, Str::Interpol, :pop!
  169.        mixin :php
  170.      end
  171.    end
  172.  end
  173. end
  174.  
downloadphp.rb Source code - Download rouge Source code
Related Source Codes/Software:
spring-security-oauth - Support for adding OAuth1(a) and OAuth2 features (... 2017-04-23
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
sphinx_rtd_theme - Sphinx theme for readthedocs.org 2017-04-23
BlurEffectForAndroidDesign - Sample to show how to implement blur graphical tri... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
browser-diet - 2017-04-30
react-music - Make beats with React! http... 2017-04-30
java-code-styles - IntelliJ IDEA code style settings for Square's Jav... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
jo - JSON output from a shell 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
boto3 - AWS SDK for Python http://a... 2017-04-30
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29
gotraining - Go Training Class Material : ... 2017-04-29

 Back to top