Skip to content

Commit d58d2ae

Browse files
F#: Improved character literals (#1956)
This adds support for all F# character escapes which should result in all characters being highlighted as such. The problem was that character literals with escape sequences longer than two characters were not recognized.
1 parent 11f18e3 commit d58d2ae

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

components/prism-fsharp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Prism.languages.fsharp = Prism.languages.extend('clike', {
1010
}
1111
],
1212
'string': {
13-
pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\.)'B?/,
13+
pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,
1414
greedy: true
1515
},
1616
'class-name': {

components/prism-fsharp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-fsharp.html

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ <h2>Comments</h2>
55

66
<h2>Strings</h2>
77
<pre><code>"foo \"bar\" baz"
8-
'foo \'bar\' baz'
98
@"Verbatim strings"
109
"""Alternate "verbatim" strings"""
1110
</code></pre>
@@ -58,32 +57,32 @@ <h2>Numbers</h2>
5857
</code></pre>
5958

6059
<h2>Full example</h2>
61-
<pre><code>// The declaration creates a constructor that takes two values, name and age.
60+
<pre><code>// The declaration creates a constructor that takes two values, name and age.
6261
type Person(name:string, age:int) =
63-
// A Person object's age can be changed. The mutable keyword in the
64-
// declaration makes that possible.
62+
// A Person object's age can be changed. The mutable keyword in the
63+
// declaration makes that possible.
6564
let mutable internalAge = age
6665

67-
// Declare a second constructor that takes only one argument, a name.
68-
// This constructor calls the constructor that requires two arguments,
69-
// sending 0 as the value for age.
66+
// Declare a second constructor that takes only one argument, a name.
67+
// This constructor calls the constructor that requires two arguments,
68+
// sending 0 as the value for age.
7069
new(name:string) = Person(name, 0)
7170

72-
// A read-only property.
71+
// A read-only property.
7372
member this.Name = name
74-
// A read/write property.
73+
// A read/write property.
7574
member this.Age
7675
with get() = internalAge
7776
and set(value) = internalAge &lt;- value
7877

79-
// Instance methods.
80-
// Increment the person's age.
78+
// Instance methods.
79+
// Increment the person's age.
8180
member this.HasABirthday () = internalAge &lt;- internalAge + 1
8281

83-
// Check current age against some threshold.
82+
// Check current age against some threshold.
8483
member this.IsOfAge targetAge = internalAge &gt;= targetAge
8584

86-
// Display the person's name and age.
87-
override this.ToString () =
85+
// Display the person's name and age.
86+
override this.ToString () =
8887
"Name: " + name + "\n" + "Age: " + (string)internalAge
89-
</code></pre>
88+
</code></pre>

tests/languages/fsharp/string_feature.test

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ bar"""
1818
'a'B
1919
'\''
2020
'\\'
21+
'\231'
22+
'\x41'
23+
'\u0041'
24+
'\U0001F47D'
2125

2226
----------------------------------------------------
2327

@@ -39,9 +43,13 @@ bar"""
3943
["string", "'a'"],
4044
["string", "'a'B"],
4145
["string", "'\\''"],
42-
["string", "'\\\\'"]
46+
["string", "'\\\\'"],
47+
["string", "'\\231'"],
48+
["string", "'\\x41'"],
49+
["string", "'\\u0041'"],
50+
["string", "'\\U0001F47D'"]
4351
]
4452

4553
----------------------------------------------------
4654

47-
Checks for normal strings, verbatim strings, triple-quoted strings and character literals.
55+
Checks for normal strings, verbatim strings, triple-quoted strings and character literals.

0 commit comments

Comments
 (0)