Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/rouge/lexers/dylan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
46 changes: 46 additions & 0 deletions spec/visual/samples/dylan
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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(<number>), #key from = 0, by = \+)
=> (new-collector :: <box>,
add-first :: <function>,
add-last :: <function>,
add-sequence-first :: <function>,
add-sequence-last :: <function>,
collection :: <function>)
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 :: <condition>, s :: <stream>) => ()
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;