summaryrefslogtreecommitdiffstats
path: root/vendor/plugins
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-18 17:39:12 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-18 17:39:12 +0000
commit3e102f281da906745fe1c78a603ad747db497d68 (patch)
tree77a18cb65c920c2f1ba0b621f0dd3af5f0fbe544 /vendor/plugins
parent7673d69b96cff840b0b6bce748fdb4887883aeb0 (diff)
downloadredmine-3e102f281da906745fe1c78a603ad747db497d68.tar.gz
redmine-3e102f281da906745fe1c78a603ad747db497d68.zip
Add a simple java scanner.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1272 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor/plugins')
-rw-r--r--vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb1
-rw-r--r--vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/java.rb130
2 files changed, 131 insertions, 0 deletions
diff --git a/vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb b/vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb
index 5177a9353..7e65fe425 100644
--- a/vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb
+++ b/vendor/plugins/coderay-0.7.6.227/lib/coderay/helpers/file_type.rb
@@ -84,6 +84,7 @@ module FileType
'cpp' => :c,
'c' => :c,
'h' => :c,
+ 'java' => :java,
'js' => :javascript,
'xml' => :xml,
'htm' => :html,
diff --git a/vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/java.rb b/vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/java.rb
new file mode 100644
index 000000000..4c9ac0060
--- /dev/null
+++ b/vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/java.rb
@@ -0,0 +1,130 @@
+module CodeRay
+ module Scanners
+ class Java < Scanner
+
+ register_for :java
+
+ RESERVED_WORDS = %w(abstract assert break case catch class
+ const continue default do else enum extends final finally for
+ goto if implements import instanceof interface native new
+ package private protected public return static strictfp super switch
+ synchronized this throw throws transient try void volatile while)
+
+ PREDEFINED_TYPES = %w(boolean byte char double float int long short)
+
+ PREDEFINED_CONSTANTS = %w(true false null)
+
+ IDENT_KIND = WordList.new(:ident).
+ add(RESERVED_WORDS, :reserved).
+ add(PREDEFINED_TYPES, :pre_type).
+ add(PREDEFINED_CONSTANTS, :pre_constant)
+
+ ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
+
+ def scan_tokens tokens, options
+ state = :initial
+
+ until eos?
+ kind = nil
+ match = nil
+
+ case state
+ when :initial
+
+ if scan(/ \s+ | \\\n /x)
+ kind = :space
+
+ elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
+ kind = :comment
+
+ elsif match = scan(/ \# \s* if \s* 0 /x)
+ match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
+ kind = :comment
+
+ elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
+ kind = :operator
+
+ elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
+ kind = IDENT_KIND[match]
+ if kind == :ident and check(/:(?!:)/)
+ match << scan(/:/)
+ kind = :label
+ end
+
+ elsif match = scan(/L?"/)
+ tokens << [:open, :string]
+ if match[0] == ?L
+ tokens << ['L', :modifier]
+ match = '"'
+ end
+ state = :string
+ kind = :delimiter
+
+ elsif scan(%r! \@ .* !x)
+ kind = :preprocessor
+
+ elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
+ kind = :char
+
+ elsif scan(/0[xX][0-9A-Fa-f]+/)
+ kind = :hex
+
+ elsif scan(/(?:0[0-7]+)(?![89.eEfF])/)
+ kind = :oct
+
+ elsif scan(/(?:\d+)(?![.eEfF])/)
+ kind = :integer
+
+ elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
+ kind = :float
+
+ else
+ getch
+ kind = :error
+
+ end
+
+ when :string
+ if scan(/[^\\\n"]+/)
+ kind = :content
+ elsif scan(/"/)
+ tokens << ['"', :delimiter]
+ tokens << [:close, :string]
+ state = :initial
+ next
+ elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
+ kind = :char
+ elsif scan(/ \\ | $ /x)
+ tokens << [:close, :string]
+ kind = :error
+ state = :initial
+ else
+ raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
+ end
+
+ else
+ raise_inspect 'Unknown state', tokens
+
+ end
+
+ match ||= matched
+ if $DEBUG and not kind
+ raise_inspect 'Error token %p in line %d' %
+ [[match, kind], line], tokens
+ end
+ raise_inspect 'Empty token', tokens unless match
+
+ tokens << [match, kind]
+
+ end
+
+ if state == :string
+ tokens << [:close, :string]
+ end
+
+ tokens
+ end
+ end
+ end
+end