Skip to content

Commit 50971f5

Browse files
jneenjneen
andauthored
Dylan: add operator escapes and string hex escapes (#2250)
* add operator escapes and string hex escapes * use the word var * support unary ~ * add sample to dylan * add a more detailed test string for DIF --------- Co-authored-by: jneen <[email protected]>
1 parent 74bfc22 commit 50971f5

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

lib/rouge/lexers/dylan.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ class Dylan < RegexLexer
7070
rule %r/[+-]?[0-9]+/, Literal::Number::Integer
7171
rule %r/#x[0-9a-f]+/i, Literal::Number::Hex
7272

73-
# Names
74-
rule %r/[+-]/, Operator
75-
7673
# Operators and punctuation
7774
rule %r/::|=>|#[(\[#]|[.][.][.]|[(),.;\[\]{}=?]/, Punctuation
7875

79-
rule %r([\w!&*<>|^\$%@][\w!&*<>|^\$%@=/?~+-]*) do |m|
76+
word_re = %r([\w!&*<>|^\$%@][\w!&*<>|^\$%@=/?~+-]*|[+-~])
77+
78+
rule %r/\\#{word_re}/, Str::Symbol
79+
80+
rule word_re do |m|
8081
word = m[0]
81-
if operators.include?(m[0])
82+
if operators.include?(word)
8283
token Operator
8384
elsif word.start_with?('<') && word.end_with?('>')
8485
token Name::Class
@@ -99,6 +100,7 @@ class Dylan < RegexLexer
99100

100101
state :dq do
101102
rule %r/\\[\\'"abefnrt0]/, Str::Escape
103+
rule %r/\\<\h+>/, Str::Escape
102104
rule %r/[^\\"]+/, Str::Double
103105
rule %r/"/, Str::Double, :pop!
104106
end

spec/visual/samples/dylan

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc.
66
License: See License.txt in this distribution for details.
77
Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
88

9+
this string is a continuation of Warranty because the line starts with a space.
10+
it should be highlighted as a Comment.
11+
12+
"this string is not a comment because it doesn't start with a space";
13+
914
///
1015
/// The canonical recursive function.
1116
///
@@ -49,3 +54,44 @@ define function factorial-top-level () => ()
4954
end function factorial-top-level;
5055

5156
factorial-top-level();
57+
58+
59+
// https://github.com/dylan-lang/opendylan/blob/85fc782bf2b1390929bdb9fc98f88e5e55d7a742/sources/collections/collectors.dylan#L160-L180
60+
define inline method collector-protocol
61+
(class :: subclass(<number>), #key from = 0, by = \+)
62+
=> (new-collector :: <box>,
63+
add-first :: <function>,
64+
add-last :: <function>,
65+
add-sequence-first :: <function>,
66+
add-sequence-last :: <function>,
67+
collection :: <function>)
68+
values(box(from),
69+
method (collector, value)
70+
collector.object := by(value, collector.object);
71+
end,
72+
method (collector, value)
73+
collector.object := by(collector.object, value);
74+
end,
75+
sequence-collection-not-yet-implemented,
76+
sequence-collection-not-yet-implemented,
77+
method (collector)
78+
collector.object
79+
end)
80+
end method;
81+
82+
// hex escapes
83+
"a string with \<01eF> a hex escape"
84+
85+
// https://github.com/dylan-lang/opendylan/blob/85fc782bf2b1390929bdb9fc98f88e5e55d7a742/sources/io/format-condition.dylan#L9-L20
86+
define sideways method print-object (c :: <condition>, s :: <stream>) => ()
87+
let message = condition-to-string(c);
88+
if (*print-escape?* | ~message)
89+
printing-object (c, s)
90+
if (message)
91+
format(s, ": %s", message)
92+
end
93+
end
94+
else
95+
write(s, message)
96+
end
97+
end method print-object;

0 commit comments

Comments
 (0)