Skip to content

Commit 670849b

Browse files
committed
enh(autodetect) r: detect <-, illegal: ->
1 parent 1c98d47 commit 670849b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/languages/r.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Website: https://www.r-project.org
77
Category: scientific
88
*/
99

10+
import * as regex from '../lib/regex.js';
11+
1012
export default function(hljs) {
1113
// Identifiers in R cannot start with `_`, but they can start with `.` if it
1214
// is not immediately followed by a digit.
@@ -15,10 +17,13 @@ export default function(hljs) {
1517
// handled in a separate mode. See `test/markup/r/names.txt` for examples.
1618
// FIXME: Support Unicode identifiers.
1719
const IDENT_RE = /(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/;
20+
const SIMPLE_IDENT = /[a-zA-Z][a-zA-Z_0-9]*/;
1821

1922
return {
2023
name: 'R',
2124

25+
// only in Haskell, not R
26+
illegal: /->/,
2227
keywords: {
2328
$pattern: IDENT_RE,
2429
keyword:
@@ -168,7 +173,10 @@ export default function(hljs) {
168173
begin: '%',
169174
end: '%'
170175
},
171-
176+
// relevance boost for assignment
177+
{
178+
begin: regex.concat(SIMPLE_IDENT, "\\s+<-\\s+")
179+
},
172180
{
173181
// escaped identifier
174182
begin: '`',

0 commit comments

Comments
 (0)