lib/rouge/lexers/php.rb in rouge-0.1.2 vs lib/rouge/lexers/php.rb in rouge-0.2.0

- old
+ new

@@ -1,19 +1,23 @@ module Rouge module Lexers - class PHP < RegexLexer + class PHP < TemplateLexer tag 'php' aliases 'php', 'php3', 'php4', 'php5' filenames '*.php', '*.php[345]' mimetypes 'text/x-php' + default_options :parent => 'html' + def initialize(opts={}) # if truthy, the lexer starts highlighting with php code # (no <?php required) @start_inline = opts.delete(:start_inline) @funcnamehighlighting = opts.delete(:funcnamehighlighting) { true } @disabledmodules = opts.delete(:disabledmodules) { [] } + + super(opts) end def builtins return [] unless @funcnamehighlighting @@ -46,13 +50,12 @@ php_user_filter interface implements public private protected abstract clone try catch throw this use namespace ) state :root do - rule /<\?(php)?/, 'Comment.Preproc', :php - rule /.*?(?=<\?)/, 'Other' - rule /</, 'Other' + rule /<\?(php|=)?/, 'Comment.Preproc', :php + rule(/.*?(?=<\?)|.*/m) { delegate parent } end state :php do rule /\?>/, 'Comment.Preproc', :pop! # heredocs @@ -138,18 +141,13 @@ state :interp_single do rule /\}/, 'Literal.String.Interpol', :pop! mixin :php end - def stream_tokens(source, &b) - super(source) do |tok, val| - if tok.name == 'Name.Other' and builtins.include? val - yield [Token['Name.Builtin'], val] - else - yield [tok, val] - end - end + postprocess 'Name.Other' do |tok, val| + tok = 'Name.Builtin' if builtins.include? val + + token tok, val end end end end -