summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/coderay/scanners/ruby/patterns.rb23
-rw-r--r--test/scanners/ruby/strange.expected.raydebug8
-rw-r--r--test/scanners/ruby/strange.in.rb8
3 files changed, 30 insertions, 9 deletions
diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb
index 98e4e93..e303894 100644
--- a/lib/coderay/scanners/ruby/patterns.rb
+++ b/lib/coderay/scanners/ruby/patterns.rb
@@ -81,25 +81,30 @@ module Scanners
/ox
METHOD_NAME_OR_SYMBOL = / #{METHOD_NAME_EX} | #{SYMBOL} /ox
- # 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 = /
+ SIMPLE_ESCAPE = /
[abefnrstv]
- | (?:M-|C-|c) .?
| [0-7]{1,3}
| x[0-9A-Fa-f]{1,2}
- | .
+ | .?
/mx
-
+
+ CONTROL_META_ESCAPE = /
+ (?: M-|C-|c )
+ (?: \\ (?: M-|C-|c ) )*
+ (?: [^\\] | \\ #{SIMPLE_ESCAPE} )?
+ /mox
+
+ ESCAPE = /
+ #{CONTROL_META_ESCAPE} | #{SIMPLE_ESCAPE}
+ /mox
+
CHARACTER = /
\?
(?:
[^\s\\]
| \\ #{ESCAPE}
)
- /mx
+ /mox
# NOTE: This is not completely correct, but
# nobody needs heredoc delimiters ending with \n.
diff --git a/test/scanners/ruby/strange.expected.raydebug b/test/scanners/ruby/strange.expected.raydebug
index fa39d8a..3aa1c01 100644
--- a/test/scanners/ruby/strange.expected.raydebug
+++ b/test/scanners/ruby/strange.expected.raydebug
@@ -115,6 +115,14 @@ that)delimiter(
this)>
ident(that)
+comment(# control and meta)
+string<delimiter(")char(\\ca)delimiter(")> comment(# ")
+string<delimiter(")char(\\c\\3)delimiter(")> comment(# ")
+string<delimiter(")char(\\c")delimiter(")> comment(# ")
+string<delimiter(")char(\\M-")delimiter(")> comment(# ")
+string<delimiter(")char(\\C-")delimiter(")> comment(# ")
+string<delimiter(")char(\\C-\\M-\\c\\M-\\C-a)delimiter(")> operator(==) string<delimiter(")char(\\201)delimiter(")> comment(# ")
+
comment(##################################################################)
reserved(class) class(NP)
reserved(def) method(initialize) ident(a)operator(=)instance_variable(@p)operator(=)operator([)operator(])operator(,) ident(b)operator(=)instance_variable(@b)operator(=)operator([)operator(])operator(;) reserved(end)
diff --git a/test/scanners/ruby/strange.in.rb b/test/scanners/ruby/strange.in.rb
index bf57322..1b4ba0e 100644
--- a/test/scanners/ruby/strange.in.rb
+++ b/test/scanners/ruby/strange.in.rb
@@ -115,6 +115,14 @@ that
this
that
+# control and meta
+"\ca" # "
+"\c\3" # "
+"\c"" # "
+"\M-"" # "
+"\C-"" # "
+"\C-\M-\c\M-\C-a" == "\201" # "
+
##################################################################
class NP
def initialize a=@p=[], b=@b=[]; end