@@ -22,6 +22,12 @@ class RDoc::RubyLex
2222
2323 # :stopdoc:
2424
25+ ##
26+ # Raised upon invalid input
27+
28+ class Error < RDoc ::Error
29+ end
30+
2531 extend Exception2MessageMapper
2632
2733 def_exception ( :AlreadyDefinedToken , "Already defined token(%s)" )
@@ -50,6 +56,19 @@ def self.debug?
5056
5157 self . debug_level = 0
5258
59+ def self . tokenize text , options
60+ tokens = [ ]
61+
62+ scanner = RDoc ::RubyLex . new text , options
63+ scanner . exception_on_syntax_error = true
64+
65+ while token = scanner . token do
66+ tokens << token
67+ end
68+
69+ tokens
70+ end
71+
5372 def initialize ( content , options )
5473 lex_init
5574
@@ -322,7 +341,7 @@ def token
322341 tk = @OP . match ( self )
323342 @space_seen = tk . kind_of? ( TkSPACE )
324343 rescue SyntaxError => e
325- raise RDoc :: Error , "syntax error: #{ e . message } " if
344+ raise Error , "syntax error: #{ e . message } " if
326345 @exception_on_syntax_error
327346
328347 tk = TkError . new ( @seek , @line_no , @char_no )
@@ -1004,7 +1023,7 @@ def identify_quotation
10041023 elsif ch =~ /\W /
10051024 lt = "\" "
10061025 else
1007- raise RDoc :: Error , "unknown type of %string #{ ch . inspect } "
1026+ raise Error , "unknown type of %string #{ ch . inspect } "
10081027 end
10091028 # if ch !~ /\W/
10101029 # ungetc
@@ -1039,7 +1058,7 @@ def identify_number(op = "")
10391058 when /[0-7]/
10401059 match = /[0-7_]/
10411060 when /[89]/
1042- raise RDoc :: Error , "Illegal octal digit"
1061+ raise Error , "Illegal octal digit"
10431062 else
10441063 return Token ( TkINTEGER , num )
10451064 end
@@ -1053,7 +1072,7 @@ def identify_number(op = "")
10531072 if match =~ ch
10541073 if ch == "_"
10551074 if non_digit
1056- raise RDoc :: Error , "trailing `#{ ch } ' in number"
1075+ raise Error , "trailing `#{ ch } ' in number"
10571076 else
10581077 non_digit = ch
10591078 end
@@ -1065,10 +1084,10 @@ def identify_number(op = "")
10651084 ungetc
10661085 num [ -1 , 1 ] = ''
10671086 if len0
1068- raise RDoc :: Error , "numeric literal without digits"
1087+ raise Error , "numeric literal without digits"
10691088 end
10701089 if non_digit
1071- raise RDoc :: Error , "trailing `#{ non_digit } ' in number"
1090+ raise Error , "trailing `#{ non_digit } ' in number"
10721091 end
10731092 break
10741093 end
@@ -1089,7 +1108,7 @@ def identify_number(op = "")
10891108 non_digit = ch
10901109 when allow_point && "."
10911110 if non_digit
1092- raise RDoc :: Error , "trailing `#{ non_digit } ' in number"
1111+ raise Error , "trailing `#{ non_digit } ' in number"
10931112 end
10941113 type = TkFLOAT
10951114 if peek ( 0 ) !~ /[0-9]/
@@ -1101,7 +1120,7 @@ def identify_number(op = "")
11011120 allow_point = false
11021121 when allow_e && "e" , allow_e && "E"
11031122 if non_digit
1104- raise RDoc :: Error , "trailing `#{ non_digit } ' in number"
1123+ raise Error , "trailing `#{ non_digit } ' in number"
11051124 end
11061125 type = TkFLOAT
11071126 if peek ( 0 ) =~ /[+-]/
@@ -1112,7 +1131,7 @@ def identify_number(op = "")
11121131 non_digit = ch
11131132 else
11141133 if non_digit
1115- raise RDoc :: Error , "trailing `#{ non_digit } ' in number"
1134+ raise Error , "trailing `#{ non_digit } ' in number"
11161135 end
11171136 ungetc
11181137 num [ -1 , 1 ] = ''
0 commit comments