diff --git a/lib/rouge/lexers/dylan.rb b/lib/rouge/lexers/dylan.rb index 1967db7ade..997d44a9be 100644 --- a/lib/rouge/lexers/dylan.rb +++ b/lib/rouge/lexers/dylan.rb @@ -70,15 +70,16 @@ class Dylan < RegexLexer rule %r/[+-]?[0-9]+/, Literal::Number::Integer rule %r/#x[0-9a-f]+/i, Literal::Number::Hex - # Names - rule %r/[+-]/, Operator - # Operators and punctuation rule %r/::|=>|#[(\[#]|[.][.][.]|[(),.;\[\]{}=?]/, Punctuation - rule %r([\w!&*<>|^\$%@][\w!&*<>|^\$%@=/?~+-]*) do |m| + word_re = %r([\w!&*<>|^\$%@][\w!&*<>|^\$%@=/?~+-]*|[+-~]) + + rule %r/\\#{word_re}/, Str::Symbol + + rule word_re do |m| word = m[0] - if operators.include?(m[0]) + if operators.include?(word) token Operator elsif word.start_with?('<') && word.end_with?('>') token Name::Class @@ -99,6 +100,7 @@ class Dylan < RegexLexer state :dq do rule %r/\\[\\'"abefnrt0]/, Str::Escape + rule %r/\\<\h+>/, Str::Escape rule %r/[^\\"]+/, Str::Double rule %r/"/, Str::Double, :pop! end diff --git a/spec/visual/samples/dylan b/spec/visual/samples/dylan index 2ba41b416d..51a2b27017 100644 --- a/spec/visual/samples/dylan +++ b/spec/visual/samples/dylan @@ -6,6 +6,11 @@ Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. License: See License.txt in this distribution for details. Warranty: Distributed WITHOUT WARRANTY OF ANY KIND + this string is a continuation of Warranty because the line starts with a space. + it should be highlighted as a Comment. + +"this string is not a comment because it doesn't start with a space"; + /// /// The canonical recursive function. /// @@ -49,3 +54,44 @@ define function factorial-top-level () => () end function factorial-top-level; factorial-top-level(); + + +// https://github.com/dylan-lang/opendylan/blob/85fc782bf2b1390929bdb9fc98f88e5e55d7a742/sources/collections/collectors.dylan#L160-L180 +define inline method collector-protocol + (class :: subclass(), #key from = 0, by = \+) + => (new-collector :: , + add-first :: , + add-last :: , + add-sequence-first :: , + add-sequence-last :: , + collection :: ) + values(box(from), + method (collector, value) + collector.object := by(value, collector.object); + end, + method (collector, value) + collector.object := by(collector.object, value); + end, + sequence-collection-not-yet-implemented, + sequence-collection-not-yet-implemented, + method (collector) + collector.object + end) +end method; + +// hex escapes +"a string with \<01eF> a hex escape" + +// https://github.com/dylan-lang/opendylan/blob/85fc782bf2b1390929bdb9fc98f88e5e55d7a742/sources/io/format-condition.dylan#L9-L20 +define sideways method print-object (c :: , s :: ) => () + let message = condition-to-string(c); + if (*print-escape?* | ~message) + printing-object (c, s) + if (message) + format(s, ": %s", message) + end + end + else + write(s, message) + end +end method print-object;