Permalink
Browse files

version 1.8.5: fixed bug in InteractiveStringStream and updated sampl…

…e JavaScript grammar

1.  Fixed ANTLR3::InteractiveStringStream to work with Ruby 1.9
    files:
      - modified: lib/antlr3/streams/interactive.rb
    notes:
      - the InteractiveStringStream class is used to implement
        the interactive mode of the lexer Main programs
      - after updating StringStream to work with Ruby 1.9, I never
        updated this class to reflect the change in structure
      - updated the class to mirror the structural changes in StringStream

2.  Updated sample JavaScript grammar to correct a few issues
    files:
      - modified: samples/JavaScript.g
  • Loading branch information...
1 parent 9fc3bf4 commit 2cd528224a891a2034e65e272ba086707b7a029f Kyle Yetter committed Oct 22, 2010
View
@@ -1,3 +1,9 @@
+=== 1.8.5 / 10-21-10
+
+* 1 Bug Fix
+ - fixed ANTLR3::InteractiveStringStream to work with Ruby 1.9. The lexer main script
+ should function in interactive mode for Ruby 1.9 now.
+
=== 1.8.4 / 10-08-10
* 1 Bug Fix
View
@@ -4,7 +4,7 @@
#
name: antlr3
-version: "1.8.4"
+version: "1.8.5"
antlr_version: "3.2.1"
summary: |-
@@ -11,17 +11,82 @@ module ANTLR3
=end
class InteractiveStringStream < StringStream
- def initialize( options = {}, &block )
- @data = ''
- @position = @column = @mark_depth = 0
- @line = 1
- @markers = []
- mark
- @initialized = @eof = false
- @readline = block or raise( ArgumentError, "no line-reading block was provided" )
- @name = options.fetch( :name, '(interactive)' )
+
+ if RUBY_VERSION =~ /^1\.9/
+
+ # creates a new StringStream object where +data+ is the string data to stream.
+ # accepts the following options in a symbol-to-value hash:
+ #
+ # [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
+ # [:line] the initial line number; default: +1+
+ # [:column] the initial column number; default: +0+
+ #
+ def initialize( options = {}, &block ) # for 1.9
+ @string = ''
+ @data = []
+ @position = options.fetch :position, 0
+ @line = options.fetch :line, 1
+ @column = options.fetch :column, 0
+ @markers = []
+ mark
+ @initialized = @eof = false
+ @readline = block or raise( ArgumentError, "no line-reading block was provided" )
+ @name ||= options[ :file ] || options[ :name ] || '(interactive)'
+ end
+
+ def readline
+ @initialized = true
+ unless @eof
+ if line = @readline.call
+ line = line.to_s.encode( Encoding::UTF_8 )
+ @string << line
+ @data.concat( line.codepoints.to_a )
+ return true
+ else
+ @eof = true
+ return false
+ end
+ end
+ end
+
+ else
+
+ # creates a new StringStream object where +data+ is the string data to stream.
+ # accepts the following options in a symbol-to-value hash:
+ #
+ # [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
+ # [:line] the initial line number; default: +1+
+ # [:column] the initial column number; default: +0+
+ #
+ def initialize( options = {}, &block )
+ @string = @data = ''
+ @position = options.fetch :position, 0
+ @line = options.fetch :line, 1
+ @column = options.fetch :column, 0
+ @markers = []
+ mark
+ @initialized = @eof = false
+ @readline = block or raise( ArgumentError, "no line-reading block was provided" )
+ @name ||= options[ :file ] || options[ :name ] || '(interactive)'
+ end
+
+ def readline
+ @initialized = true
+ unless @eof
+ if line = @readline.call
+ @data << line.to_s
+ return true
+ else
+ @eof = true
+ return false
+ end
+ end
+ end
+
end
+ private :readline
+
def consume
@position < @data.size and return( super )
unless @eof
@@ -50,28 +115,15 @@ def look( i = 1 )
def substring( start, stop )
fill_through( stop )
- @data[ start..stop ]
+ @string[ start .. stop ]
end
private
def fill_through( position )
@eof and return
- if position < 0 then fill_out
- else readline until ( @data.size > position or @eof )
- end
- end
-
- def readline
- @initialized = true
- unless @eof
- if line = @readline.call
- @data << line.to_s
- return true
- else
- @eof = true
- return false
- end
+ if @position < 0 then fill_out
+ else readline until ( @data.size > @position or @eof )
end
end
View
@@ -377,7 +377,7 @@ def define_tasks( shared_depends )
depends = shared_depends + depends
target_files.each do | target |
- file( target => depends ) do
+ file( target => ( depends - [ target ] ) ) do # prevents recursive .tokens file dependencies
@group.compile( self )
end
end
View
@@ -20,7 +20,7 @@ module ANTLR3
#
MAJOR_VERSION = 1
MINOR_VERSION = 8
- PATCH_VERSION = 4
+ PATCH_VERSION = 5
VERSION = [ MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION ]
VERSION_STRING = VERSION.join( '.' ).freeze
Oops, something went wrong.

0 comments on commit 2cd5282

Please sign in to comment.