Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 9b8047f

Browse files
author
mikesamuel@gmail.com
committed
issue 233 : patch for R / S language support
1 parent 585e375 commit 9b8047f

4 files changed

Lines changed: 106 additions & 1 deletion

File tree

CHANGES.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ <h2>29 March 2011</h2>
153153
</ul>
154154
<h2>4 February 2013</h2>
155155
<ul>
156-
<li>Language handlers for Dart, TCL.</li>
156+
<li>Language handlers for Dart, TCL, R.</li>
157157
<li>Bug fix: VB REM style comments</li>
158158
<li>Bug fix: CSS color literals / ID selector confusion.</li>
159159
</ul>

src/lang-n.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @author Zimin A.V.
2121
*/
2222
(function () {
23+
// http://nemerle.org/wiki/index.php?title=Base_keywords
2324
var keywords = 'abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|'
2425
+ 'fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|'
2526
+ 'null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|'

src/lang-r.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (C) 2012 Jeffrey B. Arnold
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
/**
17+
* @fileoverview
18+
* Registers a language handler for S, S-plus, and R source code.
19+
*
20+
*
21+
* To use, include prettify.js and this file in your HTML page.
22+
* Then put your code in an HTML tag like
23+
* <pre class="prettyprint lang-r"> code </pre>
24+
*
25+
* Language definition from
26+
* http://cran.r-project.org/doc/manuals/R-lang.html.
27+
* Many of the regexes are shared with the pygments SLexer,
28+
* http://pygments.org/.
29+
*
30+
* Original: https://raw.github.com/jrnold/prettify-lang-r-bugs/master/lang-r.js
31+
*
32+
* @author jeffrey.arnold@gmail.com
33+
*/
34+
PR['registerLangHandler'](
35+
PR['createSimpleLexer'](
36+
[
37+
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
38+
[PR['PR_STRING'], /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"'],
39+
[PR['PR_STRING'], /^\'(?:[^\'\\]|\\[\s\S])*(?:\'|$)/, null, "'"]
40+
],
41+
[
42+
[PR['PR_COMMENT'], /^#.*/],
43+
[PR['PR_KEYWORD'], /^(?:if|else|for|while|repeat|in|next|break|return|switch|function)(?![A-Za-z0-9_.])/],
44+
// hex numbes
45+
[PR['PR_LITERAL'], /^0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/],
46+
// Decimal numbers
47+
[PR['PR_LITERAL'], /^[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?/],
48+
// builtin symbols
49+
[PR['PR_LITERAL'], /^(?:NULL|NA(?:_(?:integer|real|complex|character)_)?|Inf|TRUE|FALSE|NaN|\.\.(?:\.|[0-9]+))(?![A-Za-z0-9_.])/],
50+
// assignment, operators, and parens, etc.
51+
[PR['PR_PUNCTUATION'], /^(?:<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\*|\+|\^|\/|!|%.*?%|=|~|\$|@|:{1,3}|[\[\](){};,?])/],
52+
// valid variable names
53+
[PR['PR_PLAIN'], /^(?:[A-Za-z]+[A-Za-z0-9_.]*|\.[a-zA-Z_][0-9a-zA-Z\._]*)(?![A-Za-z0-9_.])/],
54+
// string backtick
55+
[PR['PR_STRING'], /^`.+`/]
56+
]),
57+
['r', 's', 'R', 'S', 'Splus']);

src/lang-rd.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2012 Jeffrey Arnold
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @fileoverview
17+
* Support for R documentation (Rd) files
18+
*
19+
* Minimal highlighting or Rd files, basically just highlighting
20+
* macros. It does not try to identify verbatim or R-like regions of
21+
* macros as that is too complicated for a lexer. Descriptions of the
22+
* Rd format can be found
23+
* http://cran.r-project.org/doc/manuals/R-exts.html and
24+
* http://developer.r-project.org/parseRd.pdf.
25+
*
26+
* @author Jeffrey Arnold
27+
*/
28+
PR['registerLangHandler'](
29+
PR['createSimpleLexer'](
30+
[
31+
// whitespace
32+
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
33+
// all comments begin with '%'
34+
[PR['PR_COMMENT'], /^%[^\r\n]*/, null, '%']
35+
],
36+
[// special macros with no args
37+
[PR['PR_LITERAL'], /^\\(?:cr|l?dots|R|tab)\b/],
38+
// macros
39+
[PR['PR_KEYWORD'], /^\\[a-zA-Z@]+/],
40+
// highlighted as macros, since technically they are
41+
[PR['PR_KEYWORD'], /^#(?:ifn?def|endif)/ ],
42+
// catch escaped brackets
43+
[PR['PR_PLAIN'], /^\\[{}]/],
44+
// punctuation
45+
[PR['PR_PUNCTUATION'], /^[{}()\[\]]+/]
46+
]),
47+
['Rd', 'rd']);

0 commit comments

Comments
 (0)