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

Commit

Permalink
Applied Nicholas Curry's patch for IE7 newlines to fix issue 104
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 21, 2010
1 parent 25f6d69 commit 819298e
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 5 deletions.
54 changes: 54 additions & 0 deletions src/lang-scala.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
* @fileoverview
* Registers a language handler for Scala.
*
* Derived from http://lampsvn.epfl.ch/svn-repos/scala/scala-documentation/trunk/src/reference/SyntaxSummary.tex
*
* @author [email protected]
*/

PR.registerLangHandler(
PR.createSimpleLexer(
[
// Whitespace
[PR.PR_PLAIN, /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
// A double or single quoted string
// or a triple double-quoted multi-line string.
[PR.PR_STRING,
/^(?:"(?:(?:""(?:""?(?!")|[^\\"]|\\.)*"{0,3})|(?:[^"\r\n\\]|\\.)*"?))/,
null, '"'],
[PR.PR_LITERAL, /^`(?:[^\r\n\\`]|\\.)*`?/, null, '`'],
[PR.PR_PUNCTUATION, /^[!#%&()*+,\-:;<=>?@\[\\\]^{|}~]+/, null,
'!#%&()*+,-:;<=>?@[\\]^{|}~']
],
[
// A symbol literal is a single quote followed by an identifier with no
// single quote following
// A character literal has single quotes on either side
[PR.PR_STRING, /^'(?:[^\r\n\\']|\\(?:'|[^\r\n']+))'/],
[PR.PR_LITERAL, /^'[a-zA-Z_$][\w$]*(?!['$\w])/],
[PR.PR_KEYWORD, /^(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|object|override|package|private|protected|requires|return|sealed|super|throw|trait|try|type|val|var|while|with|yield)\b/],
[PR.PR_LITERAL, /^(?:true|false|null|this)\b/],
[PR.PR_LITERAL, /^(?:(?:0(?:[0-7]+|X[0-9A-F]+))L?|(?:(?:0|[1-9][0-9]*)(?:(?:\.[0-9]+)?(?:E[+\-]?[0-9]+)?F?|L?))|\\.[0-9]+(?:E[+\-]?[0-9]+)?F?)/i],
// Treat upper camel case identifiers as types.
[PR.PR_TYPE, /^[$_]*[A-Z][_$A-Z0-9]*[a-z][\w$]*/],
[PR.PR_PLAIN, /^[$a-zA-Z_][\w$]*/],
[PR.PR_COMMENT, /^\/(?:\/.*|\*(?:\/|\**[^*/])*(?:\*+\/?)?)/],
[PR.PR_PUNCTUATION, /^(?:\.+|\/)/]
]),
['scala']);
6 changes: 3 additions & 3 deletions src/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ window['_pr_isIE6'] = function () {
// on IE.
// Doing this on other browsers breaks lots of stuff since \r\n is
// treated as two newlines on Firefox.
? (isIE678 === 6 ? '&#160;\r\n' : '&#160;\r')
? (isIE678 === 6 ? '&#160;\r\n' :
isIE678 === 7 ? '&#160;<br>\r' : '&#160;\r')
// IE collapses multiple adjacent <br>s into 1 line break.
// Prefix every newline with '&#160;' to prevent such behavior.
// &nbsp; is the same as &#160; but works in XML as well as HTML.
Expand Down Expand Up @@ -1360,8 +1361,7 @@ window['_pr_isIE6'] = function () {
recombineTagsAndDecorations(job);
} catch (e) {
if ('console' in window) {
console['log'](e);
console['trace']();
console['log'](e && e['stack'] ? e['stack'] : e);
}
}
}
Expand Down
120 changes: 118 additions & 2 deletions tests/prettify_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
onerror="alert('Error: failed to load ' + this.src)"></script>
<script src="../src/lang-yaml.js" type="text/javascript"
onerror="alert('Error: failed to load ' + this.src)"></script>
<script src="../src/lang-scala.js" type="text/javascript"
onerror="alert('Error: failed to load ' + this.src)"></script>
<script src="test_base.js" type="text/javascript"
onerror="alert('Error: failed to load ' + this.src)"></script>
<link rel="stylesheet" type="text/css" href="../src/prettify.css" />
Expand Down Expand Up @@ -1163,6 +1165,65 @@ <h1>YAML mode</h1>
]
: !!str "value"
}</pre>

<h1>Scala mode</h1>
<pre class="prettyprint lang-scala" id="scala">
/* comment 1 */
/*
comment 2
*/
/* comment / * comment 3 **/
// strings
"Hello, World!", "\n",
`an-identifier`, `\n`,
'A', '\n',
'aSymbol,
"""Hello,
World""", """Hello,\nWorld""",
"""Hello, "World"!""",
"""Hello, \"World\""""

// Numbers
0
0123
0xa0
0XA0L
123
123.45
1.50F
0.50
.50
123e-1
123.45e+1
1.50e2
0.50e-6
.50e+42f

// Values
false, true, null, this;

// Keywords
class MyClass;
import foo.bar;
package baz;

// From scala-lang.org/node/242
def act() {
var pongCount = 0
loop {
react {
case Ping =>
if (pongCount % 1000 == 0)
Console.println("Pong: ping "+pongCount)
sender ! Pong
pongCount = pongCount + 1
case Stop =>
Console.println("Pong: stop")
exit()
}
}
}
</pre>
</body>

<script type="text/javascript">
Expand Down Expand Up @@ -2626,7 +2687,7 @@ <h1>YAML mode</h1>
'&nbsp; &nbsp; &nbsp;`END`KWDinit_params:<br>' +
'`END`PLN&nbsp; &nbsp; &nbsp; &nbsp;`END`KWDlogType: `END`PLNspecial<br>' +
'&nbsp; `END',
yaml2: '`DEC%YAML 1.1`END`PLN<br>' +
yaml2: '`DEC%YAML 1.1`END`PLN<br>' +
'`END`DEC---<br>' +
'`END`TYP!!map`END`PLN {<br>' +
'&nbsp; `END`PUN?`END`PLN `END`TYP!!str`END`PLN `END`STR""`END`PLN<br>' +
Expand All @@ -2641,7 +2702,62 @@ <h1>YAML mode</h1>
'&nbsp; &nbsp; `END`TYP!!str`END`PLN `END`STR"key"`END`PLN<br>' +
'&nbsp; ]<br>' +
'&nbsp; `END`PUN:`END`PLN `END`TYP!!str`END`PLN `END`STR"value"`END`PLN<br>' +
'}`END'
'}`END',
scala: '`COM/* comment 1 */`END`PLN<br>' +
'`END`COM/*<br>' +
'comment 2<br>' +
'*/`END`PLN<br>' +
'`END`COM/* comment / * comment 3 **/`END`PLN<br>' +
'`END`COM// strings`END`PLN<br>' +
'`END`STR"Hello, World!"`END`PUN,`END`PLN `END`STR"\\n"`END`PUN,`END`PLN<br>' +
'`END`LIT`an-identifier``END`PUN,`END`PLN `END`LIT`\\n``END`PUN,`END`PLN<br>' +
'`END`STR\'A\'`END`PUN,`END`PLN `END`STR\'\\n\'`END`PUN,`END`PLN<br>' +
'`END`LIT\'aSymbol`END`PUN,`END`PLN<br>' +
'`END`STR"""Hello,<br>' +
'World"""`END`PUN,`END`PLN `END`STR"""Hello,\\nWorld"""`END`PUN,`END`PLN<br>' +
'`END`STR"""Hello, "World"!"""`END`PUN,`END`PLN<br>' +
'`END`STR"""Hello, \\"World\\""""`END`PLN<br>' +
'<br>' +
'`END`COM// Numbers`END`PLN<br>' +
'`END`LIT0`END`PLN<br>' +
'`END`LIT0123`END`PLN<br>' +
'`END`LIT0xa0`END`PLN<br>' +
'`END`LIT0XA0L`END`PLN<br>' +
'`END`LIT123`END`PLN<br>' +
'`END`LIT123.45`END`PLN<br>' +
'`END`LIT1.50F`END`PLN<br>' +
'`END`LIT0.50`END`PLN<br>' +
'`END`PUN.`END`LIT50`END`PLN<br>' +
'`END`LIT123e-1`END`PLN<br>' +
'`END`LIT123.45e+1`END`PLN<br>' +
'`END`LIT1.50e2`END`PLN<br>' +
'`END`LIT0.50e-6`END`PLN<br>' +
'`END`PUN.`END`LIT50e+42f`END`PLN<br>' +
'<br>' +
'`END`COM// Values`END`PLN<br>' +
'`END`LITfalse`END`PUN,`END`PLN `END`LITtrue`END`PUN,`END`PLN `END`LITnull`END`PUN,`END`PLN `END`LITthis`END`PUN;`END`PLN<br>' +
'<br>' +
'`END`COM// Keywords`END`PLN<br>' +
'`END`KWDclass`END`PLN `END`TYPMyClass`END`PUN;`END`PLN<br>' +
'`END`KWDimport`END`PLN foo`END`PUN.`END`PLNbar`END`PUN;`END`PLN<br>' +
'`END`KWDpackage`END`PLN baz`END`PUN;`END`PLN<br>' +
'<br>' +
'`END`COM// From scala-lang.org/node/242`END`PLN<br>' +
'`END`KWDdef`END`PLN act`END`PUN()`END`PLN `END`PUN{`END`PLN<br>' +
'&nbsp; `END`KWDvar`END`PLN pongCount `END`PUN=`END`PLN `END`LIT0`END`PLN<br>' +
'&nbsp; loop `END`PUN{`END`PLN<br>' +
'&nbsp; &nbsp; react `END`PUN{`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; `END`KWDcase`END`PLN `END`TYPPing`END`PLN `END`PUN=&gt;`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; `END`KWDif`END`PLN `END`PUN(`END`PLNpongCount `END`PUN%`END`PLN `END`LIT1000`END`PLN `END`PUN==`END`PLN `END`LIT0`END`PUN)`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `END`TYPConsole`END`PUN.`END`PLNprintln`END`PUN(`END`STR"Pong: ping "`END`PUN+`END`PLNpongCount`END`PUN)`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; sender `END`PUN!`END`PLN `END`TYPPong`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; pongCount `END`PUN=`END`PLN pongCount `END`PUN+`END`PLN `END`LIT1`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; `END`KWDcase`END`PLN `END`TYPStop`END`PLN `END`PUN=&gt;`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; `END`TYPConsole`END`PUN.`END`PLNprintln`END`PUN(`END`STR"Pong: stop"`END`PUN)`END`PLN<br>' +
'&nbsp; &nbsp; &nbsp; &nbsp; exit`END`PUN()`END`PLN<br>' +
'&nbsp; &nbsp; `END`PUN}`END`PLN<br>' +
'&nbsp; `END`PUN}`END`PLN<br>' +
'`END`PUN}`END'
};
</script>

Expand Down

0 comments on commit 819298e

Please sign in to comment.