From 1ee89811c7bf8fc124e318ca01a605d3dfff1589 Mon Sep 17 00:00:00 2001 From: murphy Date: Thu, 5 Feb 2009 23:45:16 +0000 Subject: Ruby scanner: Fixed rarely used \c, \C-, and \M- escape sequences. * JavaScript scanner: elaborate a comment * SimpleRegexpScanner: Just some testing with the Ruby stack. * coderay-lib.tmproj: I should just remove it from the repo... --- etc/coderay-lib.tmproj | 16 +++++----------- etc/simple_regexp_scanner.rb | 11 +++++++++++ lib/coderay/scanners/java_script.rb | 1 + lib/coderay/scanners/ruby/patterns.rb | 2 +- test/scanners/ruby/regexp.expected.raydebug | 15 ++++++++++++++- test/scanners/ruby/regexp.in.rb | 15 ++++++++++++++- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/etc/coderay-lib.tmproj b/etc/coderay-lib.tmproj index fc48f5c..858d7bc 100644 --- a/etc/coderay-lib.tmproj +++ b/etc/coderay-lib.tmproj @@ -15,8 +15,6 @@ ../lib - expanded - name bin regexFolderFilter @@ -33,8 +31,6 @@ ../ftp.yaml - expanded - name etc regexFolderFilter @@ -67,8 +63,6 @@ ../pkg - expanded - name rake_helpers regexFolderFilter @@ -77,8 +71,6 @@ ../rake_helpers - expanded - name rake_tasks regexFolderFilter @@ -90,13 +82,15 @@ filename ../Rakefile lastUsed - 2009-01-13T15:38:32Z + 2009-01-22T14:33:27Z filename ../diff lastUsed - 2009-01-13T16:07:48Z + 2009-02-02T10:25:08Z + selected + filename @@ -116,7 +110,7 @@ filename ../test/scanners/coderay_suite.rb lastUsed - 2009-01-13T15:34:57Z + 2009-01-22T13:52:45Z filename diff --git a/etc/simple_regexp_scanner.rb b/etc/simple_regexp_scanner.rb index 6e1d098..e89460e 100644 --- a/etc/simple_regexp_scanner.rb +++ b/etc/simple_regexp_scanner.rb @@ -91,6 +91,17 @@ class SimpleRegexpScannerTest < Test::Unit::TestCase assert_scans_list '(A(B(C|D))?)?', ['ABC', 'ABD', 'A', ''] end + def test_deep_recusion + n = 1_000 + assert_nothing_raised do + assert_scans_list '(' * n + ')' * n, [''] + end + n = 10_000 + assert_raise SystemStackError do + assert_scans_list '(' * n + ')' * n, [''] + end + end + JAVA_BUILTIN_TYPES = <<-TYPES.delete(" \n") (R(GBImageFilter|MI(S(ocketFactory|e(curity(Manager|Exception)|rver(SocketFactor y|Impl(_Stub)?)?))|C(onnect(ion(Impl(_Stub)?)?|or(Server)?)|l(ientSocketFactory| diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index 0187e5b..e9ae14f 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -104,6 +104,7 @@ module Scanners # TODO: string key recognition # There's a problem with expressions like: PAIRS: { 'slide': ['SlideDown','SlideUp'], ... }. + # The commas in the array are confusing the scanner here. # elsif key_expected && match = scan(/["']/) # tokens << [:open, :key] # state = :key diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index c18789b..98e4e93 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -87,7 +87,7 @@ module Scanners # assert_equal(129, ?\M-\C-a) ESCAPE = / [abefnrstv] - | M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M- + | (?:M-|C-|c) .? | [0-7]{1,3} | x[0-9A-Fa-f]{1,2} | . diff --git a/test/scanners/ruby/regexp.expected.raydebug b/test/scanners/ruby/regexp.expected.raydebug index 43f1d91..4d6086b 100644 --- a/test/scanners/ruby/regexp.expected.raydebug +++ b/test/scanners/ruby/regexp.expected.raydebug @@ -2,4 +2,17 @@ comment(# Regexp or division?) ident(some_string)operator(.)ident(to_i) regexp ident(some_string)operator(.)ident(split) operator(/) operator(+)regexp ident(some_string)operator(.)ident(split) operator(/) operator(+) regexp -ident(some_string)operator(.)ident(split) regexp comment(# and this one is a regexp without division) \ No newline at end of file +ident(some_string)operator(.)ident(split) regexp comment(# and this one is a regexp without division) + +ident(it) string reserved(do) + ident(str) operator(=) string + regexpcontent(\))delimiter(/)>operator(.)ident(should) operator(==) regexp + + ident(str) operator(=) string + regexpcontent(-z])delimiter(/)>operator(.)ident(should) operator(==) regexp + + ident(not_compliant_on)operator(()symbol(:ruby)operator(\)) reserved(do) + ident(str) operator(=) string + ident(re) operator(=) regexpoperator(.)ident(should) operator(==) regexp + reserved(end) +reserved(end) \ No newline at end of file diff --git a/test/scanners/ruby/regexp.in.rb b/test/scanners/ruby/regexp.in.rb index 956e6b8..e10e7a8 100644 --- a/test/scanners/ruby/regexp.in.rb +++ b/test/scanners/ruby/regexp.in.rb @@ -2,4 +2,17 @@ some_string.to_i /\s+/ some_string.split / +/ this is a regexp after a division / some_string.split / + / this one, too / -some_string.split /- / # and this one is a regexp without division \ No newline at end of file +some_string.split /- / # and this one is a regexp without division + +it "allows substitution to interact with other Regexp constructs" do + str = "foo)|(bar" + /(#{str})/.should == /(foo)|(bar)/ + + str = "a" + /[#{str}-z]/.should == /[a-z]/ + + not_compliant_on(:ruby) do + str = "J" + re = /\c#{str}/.should == /\cJ/ + end +end \ No newline at end of file -- cgit v1.2.1