##// END OF EJS Templates
Do not parse redmine links inside pre/code tags (#1288)....
Do not parse redmine links inside pre/code tags (#1288). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3589 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2965:4e3202d2a2c5
r3475:7203196212ae
Show More
patterns.rb
230 lines | 6.4 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 module CodeRay
module Scanners
module Ruby::Patterns # :nodoc:
RESERVED_WORDS = %w[
and def end in or unless begin
defined? ensure module redo super until
BEGIN break do next rescue then
when END case else for retry
while alias class elsif if not return
undef yield
]
DEF_KEYWORDS = %w[ def ]
UNDEF_KEYWORDS = %w[ undef ]
MODULE_KEYWORDS = %w[class module]
DEF_NEW_STATE = WordList.new(:initial).
add(DEF_KEYWORDS, :def_expected).
add(UNDEF_KEYWORDS, :undef_expected).
add(MODULE_KEYWORDS, :module_expected)
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 IDENTS_ALLOWING_REGEXP = %w[
and or not while until unless if then elsif when sub sub! gsub gsub!
scan slice slice! split
]
REGEXP_ALLOWED = WordList.new(false).
add(IDENTS_ALLOWING_REGEXP, :set)
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 PREDEFINED_CONSTANTS = %w[
nil true false self
DATA ARGV ARGF __FILE__ __LINE__
]
IDENT_KIND = WordList.new(:ident).
add(RESERVED_WORDS, :reserved).
add(PREDEFINED_CONSTANTS, :pre_constant)
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 IDENT = /[a-z_][\w_]*/i
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
METHOD_NAME = / #{IDENT} [?!]? /ox
METHOD_NAME_OPERATOR = /
\*\*? # multiplication and power
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 | [-+]@? # plus, minus
| [\/%&|^`~] # division, modulo or format strings, &and, |or, ^xor, `system`, tilde
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 | \[\]=? # array getter and setter
| << | >> # append or shift left, shift right
| <=?>? | >=? # comparison, rocket operator
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 | ===? # simple equality and case equality
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 /ox
METHOD_NAME_EX = / #{IDENT} (?:[?!]|=(?!>))? | #{METHOD_NAME_OPERATOR} /ox
INSTANCE_VARIABLE = / @ #{IDENT} /ox
CLASS_VARIABLE = / @@ #{IDENT} /ox
OBJECT_VARIABLE = / @@? #{IDENT} /ox
GLOBAL_VARIABLE = / \$ (?: #{IDENT} | [1-9]\d* | 0\w* | [~&+`'=\/,;_.<>!@$?*":\\] | -[a-zA-Z_0-9] ) /ox
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 PREFIX_VARIABLE = / #{GLOBAL_VARIABLE} |#{OBJECT_VARIABLE} /ox
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 VARIABLE = / @?@? #{IDENT} | #{GLOBAL_VARIABLE} /ox
QUOTE_TO_TYPE = {
'`' => :shell,
'/'=> :regexp,
}
QUOTE_TO_TYPE.default = :string
REGEXP_MODIFIERS = /[mixounse]*/
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 REGEXP_SYMBOLS = /[|?*+?(){}\[\].^$]/
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
DECIMAL = /\d+(?:_\d+)*/
OCTAL = /0_?[0-7]+(?:_[0-7]+)*/
HEXADECIMAL = /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/
BINARY = /0b[01]+(?:_[01]+)*/
EXPONENT = / [eE] [+-]? #{DECIMAL} /ox
FLOAT_SUFFIX = / #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? /ox
FLOAT_OR_INT = / #{DECIMAL} (?: #{FLOAT_SUFFIX} () )? /ox
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 NUMERIC = / [-+]? (?: (?=0) (?: #{OCTAL} | #{HEXADECIMAL} | #{BINARY} ) | #{FLOAT_OR_INT} ) /ox
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
SYMBOL = /
:
(?:
#{METHOD_NAME_EX}
| #{PREFIX_VARIABLE}
| ['"]
)
/ox
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 # TODO investigste \M, \c and \C escape sequences
# (?: M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M-)? (?: \\ (?: [0-7]{3} | x[0-9A-Fa-f]{2} | . ) )
# assert_equal(225, ?\M-a)
# assert_equal(129, ?\M-\C-a)
ESCAPE = /
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 [abefnrstv]
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 | M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M-
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 | [0-7]{1,3}
| x[0-9A-Fa-f]{1,2}
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 | .
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 /mx
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 CHARACTER = /
\?
(?:
[^\s\\]
| \\ #{ESCAPE}
)
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 /mx
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
# NOTE: This is not completely correct, but
# nobody needs heredoc delimiters ending with \n.
HEREDOC_OPEN = /
<< (-)? # $1 = float
(?:
( [A-Za-z_0-9]+ ) # $2 = delim
|
( ["'`\/] ) # $3 = quote, type
( [^\n]*? ) \3 # $4 = delim
)
/mx
RUBYDOC = /
=begin (?!\S)
.*?
(?: \Z | ^=end (?!\S) [^\n]* )
/mx
DATA = /
__END__$
.*?
(?: \Z | (?=^\#CODE) )
/mx
# Checks for a valid value to follow. This enables
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 # fancy_allowed in method calls.
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 VALUE_FOLLOWS = /
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 \s+
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 (?:
[%\/][^\s=]
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 |
<<-?\S
|
#{CHARACTER}
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 )
/x
RUBYDOC_OR_DATA = / #{RUBYDOC} | #{DATA} /xo
RDOC_DATA_START = / ^=begin (?!\S) | ^__END__$ /x
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 # FIXME: \s and = are only a workaround, they are still allowed
# as delimiters.
FANCY_START_SAVE = / % ( [qQwWxsr] | (?![a-zA-Z0-9\s=]) ) ([^a-zA-Z0-9]) /mx
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 FANCY_START_CORRECT = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
FancyStringType = {
'q' => [:string, false],
'Q' => [:string, true],
'r' => [:regexp, true],
's' => [:symbol, false],
'x' => [:shell, true]
}
FancyStringType['w'] = FancyStringType['q']
FancyStringType['W'] = FancyStringType[''] = FancyStringType['Q']
class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
:paren, :paren_depth, :pattern, :next_state
CLOSING_PAREN = Hash[ *%w[
( )
[ ]
< >
{ }
] ]
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 CLOSING_PAREN.values.each { |o| o.freeze } # debug, if I try to change it with <<
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 OPENING_PAREN = CLOSING_PAREN.invert
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 STRING_PATTERN = Hash.new { |h, k|
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 delim, interpreted = *k
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 delim_pattern = Regexp.escape(delim.dup)
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 if closing_paren = CLOSING_PAREN[delim]
delim_pattern << Regexp.escape(closing_paren)
end
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 special_escapes =
case interpreted
when :regexp_symbols
'| ' + REGEXP_SYMBOLS.source
when :words
'| \s'
end
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 h[k] =
if interpreted and not delim == '#'
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 / (?= [#{delim_pattern}\\] | \# [{$@] #{special_escapes} ) /mx
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 else
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 / (?= [#{delim_pattern}\\] #{special_escapes} ) /mx
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 end
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 }
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 HEREDOC_PATTERN = Hash.new { |h, k|
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 delim, interpreted, indented = *k
delim_pattern = Regexp.escape(delim.dup)
delim_pattern = / \n #{ '(?>[\ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
h[k] =
if interpreted
/ (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
else
/ (?= #{delim_pattern}() | \\ ) /mx
end
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 }
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638
def initialize kind, interpreted, delim, heredoc = false
if heredoc
pattern = HEREDOC_PATTERN[ [delim, interpreted, heredoc == :indented] ]
Jean-Philippe Lang
Reverts r3014 (CodeRay back to 0.7.6)....
r2965 delim = nil
Jean-Philippe Lang
Added syntax highlightment for repository files (using CodeRay)....
r638 else
pattern = STRING_PATTERN[ [delim, interpreted] ]
if paren = CLOSING_PAREN[delim]
delim, paren = paren, delim
paren_depth = 1
end
end
super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial
end
end unless defined? StringState
end
end
end