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