Merge pull request #1500 from ralpheav/master
Removing cm 0.93 directories
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.csharp-punctuation {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.csharp-operator {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.csharp-keyword {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.csharp-atom {
|
||||
color: brown;
|
||||
}
|
||||
|
||||
span.csharp-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.csharp-variabledef {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.csharp-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.csharp-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.csharp-comment {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.csharp-string {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: C# demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s C# highlighter.</p>
|
||||
|
||||
<p>Written by <a href="http://skilltesting.com/">Boris Gaber and Christopher Buchino</a> (<a
|
||||
href="http://skilltesting.com/codemirror-parser-license/">license</a>).</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
using System;
|
||||
|
||||
namespace Example
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a person employed at the company
|
||||
/// </summary>
|
||||
public class Employee : Person
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first name.
|
||||
/// </summary>
|
||||
/// <value>The first name.</value>
|
||||
public string FirstName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the salary.
|
||||
/// </summary>
|
||||
/// <param name="grade">The grade.</param>
|
||||
/// <returns></returns>
|
||||
public decimal CalculateSalary(int grade)
|
||||
{
|
||||
if (grade > 10)
|
||||
return 1000;
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
parserfile: ["../contrib/csharp/js/tokenizecsharp.js", "../contrib/csharp/js/parsecsharp.js"],
|
||||
stylesheet: "css/csharpcolors.css",
|
||||
path: "../../js/",
|
||||
height: "500px"
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,196 +0,0 @@
|
||||
/* Tokenizer for CSharp code */
|
||||
|
||||
var tokenizeCSharp = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
var next;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "csharp-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
// just a keyword with no indentation implications
|
||||
var keywordD = result("keyword d", "keyword");
|
||||
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
||||
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom,
|
||||
|
||||
"class": result("class", "keyword"), "namespace": result("class", "keyword"),
|
||||
|
||||
"public": keywordD, "private": keywordD, "protected": keywordD, "internal": keywordD,
|
||||
"extern": keywordD, "override": keywordD, "virtual": keywordD, "abstract": keywordD,
|
||||
"static": keywordD, "out": keywordD, "ref": keywordD, "const": keywordD,
|
||||
|
||||
"foreach": result("for", "keyword"), "using": keywordC,
|
||||
|
||||
"int": keywordD, "double": keywordD, "long": keywordD, "bool": keywordD, "char": keywordD,
|
||||
"void": keywordD, "string": keywordD, "byte": keywordD, "sbyte": keywordD, "decimal": keywordD,
|
||||
"float": keywordD, "uint": keywordD, "ulong": keywordD, "object": keywordD,
|
||||
"short": keywordD, "ushort": keywordD,
|
||||
|
||||
"get": keywordD, "set": keywordD, "value": keywordD
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
|
||||
// Wrapper around jsToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function jsTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(jsTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, inteded to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function jsToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "csharp-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "csharp-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "csharp-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "csharp-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "csharp-comment"};
|
||||
}
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "csharp-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "csharp-string"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "csharp-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "/"){
|
||||
if (source.equals("*"))
|
||||
{ source.next(); return readMultilineComment(ch); }
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (ch == "#") { // treat c# regions like comments
|
||||
nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"};
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || jsTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
@@ -1,24 +0,0 @@
|
||||
Copyright (c) 2010, Keybroker AB
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Keybroker AB nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL Keybroker AB BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,63 +0,0 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
font-size-adjust: none;
|
||||
font-style: normal;
|
||||
font-variant: normal;
|
||||
font-weight: normal;
|
||||
line-height: normal;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.freemarker-comment {
|
||||
color: #BB9977;
|
||||
}
|
||||
|
||||
span.freemarker-generic {
|
||||
}
|
||||
|
||||
span.freemarker-boundary {
|
||||
color: darkblue;
|
||||
}
|
||||
|
||||
span.freemarker-directive {
|
||||
color: darkblue;
|
||||
}
|
||||
|
||||
span.freemarker-identifier {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.freemarker-builtin {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
span.freemarker-punctuation {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.freemarker-string {
|
||||
color: darkGreen;
|
||||
}
|
||||
|
||||
span.freemarker-number {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.freemarker-error {
|
||||
color: #F00 !important;
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Freemarker demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
<style type="text/css">
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding-right: .3em;
|
||||
font-family: tahoma, arial, helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
line-height: normal;
|
||||
padding-top: .4em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s
|
||||
Freemarker parser. Written by Magnus Ljung, released under a BSD-style <a
|
||||
href="LICENSE">license</a>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
<!--
|
||||
example useless code to show Freemarker syntax highlighting
|
||||
this is multiline comment
|
||||
-->
|
||||
|
||||
<#macro join sequence separator>
|
||||
<#assign first="true"/>
|
||||
<#list sequence as entry><#if first=="true"><#assign first="false"/><#else>${separator} </#if>${entry}</#list>
|
||||
</#macro>
|
||||
|
||||
Here is some text that isn't Freemarker.
|
||||
|
||||
Let's join a list <@join ["foo", "bar", "baz"] ", "/>
|
||||
|
||||
Some expressions: ${test} ${another?test?substring(0, 12)}
|
||||
|
||||
Use alternative directive syntax:
|
||||
[#if user == "Big Joe"]
|
||||
Hello big ${user} xxx
|
||||
[/#if]
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "350px",
|
||||
parserfile: "../contrib/freemarker/js/parsefreemarker.js",
|
||||
stylesheet: "css/freemarkercolors.css",
|
||||
path: "../../js/",
|
||||
continuousScanning: 500,
|
||||
autoMatchParens: true,
|
||||
lineNumbers: true,
|
||||
markParen: function(node, ok) {
|
||||
node.style.backgroundColor = ok ? "#CCF" : "#FCC#";
|
||||
if(!ok) {
|
||||
node.style.color = "red";
|
||||
}
|
||||
},
|
||||
unmarkParen: function(node) {
|
||||
node.style.backgroundColor = "";
|
||||
node.style.color = "";
|
||||
},
|
||||
indentUnit: 4
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Groovy demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s Groovy highlighter.</p>
|
||||
|
||||
<p>Created by eXo Platform SAS (<a href="http://www.opensource.org/licenses/lgpl-2.1.php">license</a>).</p>
|
||||
|
||||
<p>Note that the files for this parser aren't included in the CodeMirror repository, but have to fetched from <a href="http://svn.exoplatform.org/">svn.exoplatform.org</a>:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/tokenizegroovy.js">tokenizegroovy.js</a></li>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/parsegroovy.js">parsegroovy.js</a></li>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/css/groovycolors.css">groovy.colors.css</a></li>
|
||||
</ul>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
// simple groovy script
|
||||
import javax.ws.rs.Path
|
||||
import javax.ws.rs.GET
|
||||
import javax.ws.rs.PathParam
|
||||
import javax.ws.rs.POST
|
||||
|
||||
@Path("/")
|
||||
public class HelloWorld {
|
||||
@GET
|
||||
@Path("helloworld/{name}")
|
||||
public String hello(@PathParam("name") String name) {
|
||||
return "Hello " + name
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("helloworld/{name}")
|
||||
public String hello2(@PathParam("name") String name) {
|
||||
return "Hello " + name
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: ["http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/parsegroovy.js", "http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/tokenizegroovy.js"],
|
||||
stylesheet: "http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/css/groovycolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,20 +0,0 @@
|
||||
Copyright (c) 2010 Patrick Wied
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
@@ -1,64 +0,0 @@
|
||||
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.java-punctuation {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.java-operator {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.java-keyword {
|
||||
color: #7f0055;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
span.java-atom {
|
||||
color: brown;
|
||||
}
|
||||
|
||||
span.java-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
|
||||
span.java-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.java-comment {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.javadoc-comment {
|
||||
color: #3e5797;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
span.java-string {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.java-annotation{
|
||||
color: gray;
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Demonstration of CodeMirrors Java highlighter written by Patrick Wied</title>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Demonstration of <a href="http://www.codemirror.net">CodeMirror</a>'s Java highlighter.</p>
|
||||
|
||||
<p>Written by <a href="http://www.patrick-wied.at/">Patrick Wied</a>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code">
|
||||
package example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* This class subclasses DrawableRect and adds colors to the rectangle it draws
|
||||
**/
|
||||
public class ColoredRect extends DrawableRect {
|
||||
// These are new fields defined by this class.
|
||||
// x1, y1, x2, and y2 are inherited from our super-superclass, Rect.
|
||||
@AnnotationTest
|
||||
protected Color border, fill;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* This constructor uses super() to invoke the superclass constructor, and
|
||||
* also does some initialization of its own.
|
||||
**/
|
||||
public ColoredRect(int x1, int y1, int x2, int y2, Color border, Color fill){
|
||||
super(x1, y1, x2, y2);
|
||||
/* This
|
||||
is a block comment */
|
||||
this.border = border;
|
||||
this.fill = fill;
|
||||
this.name = "This is a string";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method overrides the draw() method of our superclass so that it
|
||||
* can make use of the colors that have been specified.
|
||||
**/
|
||||
public void draw(Graphics g) {
|
||||
g.setColor(fill);
|
||||
g.fillRect(x1, y1, x2, y2);
|
||||
g.setColor(border);
|
||||
g.drawRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "650px",
|
||||
parserfile: ["../contrib/java/js/tokenizejava.js","../contrib/java/js/parsejava.js"],
|
||||
stylesheet: "css/javacolors.css",
|
||||
path: "../../js/",
|
||||
tabMode : "shift"
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,285 +0,0 @@
|
||||
/**
|
||||
* Java parser for codemirror
|
||||
*
|
||||
* @author Patrick Wied
|
||||
*/
|
||||
|
||||
var JavaParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms.
|
||||
var atomicTypes = {"atom": true, "number": true, "string": true, "regexp": true};
|
||||
// Setting that can be used to have JSON data indent properly.
|
||||
var json = false;
|
||||
// Constructor for the lexical context objects.
|
||||
function JavaLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ( 'stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// java indentation rules.
|
||||
function indentJava(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parseJava(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizeJava(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [statements];
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new JavaLexical(basecolumn || 0, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next'
|
||||
// function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch a token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentJava(lexical);
|
||||
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment" || token.type == "javadoc" || token.type == "annotation")
|
||||
return token;
|
||||
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume){
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, and context
|
||||
// objects are not mutated in a harmful way, so they can be shared
|
||||
// between runs of the parser.
|
||||
function copy(){
|
||||
var _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizeJava(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function(){
|
||||
lexical = new JavaLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type.
|
||||
function expect(wanted){
|
||||
return function expecting(type){
|
||||
if (type == wanted) cont();
|
||||
else cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(type){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the
|
||||
// current token.
|
||||
function statement(type){
|
||||
if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), statement, poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == "for") cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), poplex, statement, poplex);
|
||||
else if (type == "variable") cont(pushlex("stat"), maybelabel);
|
||||
else if (type == "switch") cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, expect(":"));
|
||||
else if (type == "default") cont(expect(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), expect("("), function(){}, expect(")"), statement, poplex);
|
||||
else if (type == "class") cont();
|
||||
else if (type == "interface") cont();
|
||||
else if (type == "keyword c") cont(statement);
|
||||
else pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(type){
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
//else if (type == "function") cont(functiondef);
|
||||
else if (type == "keyword c") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == "[") cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
}
|
||||
// Called for places where operators, function calls, or
|
||||
// subscripts are valid. Will skip on to the next action if none
|
||||
// is found.
|
||||
function maybeoperator(type){
|
||||
if (type == "operator") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, commasep(expression, ")"), poplex, maybeoperator);
|
||||
else if (type == "[") cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
// When a statement starts with a variable name, it might be a
|
||||
// label. If no colon follows, it's a regular statement.
|
||||
|
||||
function maybelabel(type){
|
||||
if (type == "(") cont(commasep(function(){}, ")"), poplex, statement); // method definition
|
||||
else if (type == "{") cont(poplex, pushlex("}"), block, poplex); // property definition
|
||||
else pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what, end){
|
||||
function proceed(type) {
|
||||
if (type == ",") cont(what, proceed);
|
||||
else if (type == end) cont();
|
||||
else cont(expect(end));
|
||||
};
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) cont();
|
||||
else pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(type){
|
||||
if (type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
|
||||
// For loops.
|
||||
|
||||
function forspec1(type){
|
||||
if (type == ";") pass(forspec2);
|
||||
else pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value){
|
||||
if (value == "in") cont(expression);
|
||||
else cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value){
|
||||
if (type == ";") cont(forspec3);
|
||||
else if (value == "in") cont(expression);
|
||||
else cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type == ")") pass();
|
||||
else cont(expression);
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseJava,
|
||||
electricChars: "{}:",
|
||||
configure: function(obj) {
|
||||
if (obj.json != null) json = obj.json;
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -1,222 +0,0 @@
|
||||
/**
|
||||
* Java tokenizer for codemirror
|
||||
*
|
||||
* @author Patrick Wied
|
||||
* @version 2010-10-07
|
||||
*/
|
||||
var tokenizeJava = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
var next;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of Java's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "java-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "throw": keywordC, "throws": keywordB,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"catch": result("catch", "keyword"), "for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom,
|
||||
|
||||
"class": result("class", "keyword"), "interface": result("interface", "keyword"), "package": keywordC, "import": keywordC,
|
||||
"implements": keywordC, "extends": keywordC, "super": keywordC,
|
||||
|
||||
"public": keywordC, "private": keywordC, "protected": keywordC, "transient": keywordC, "this": keywordC,
|
||||
"static": keywordC, "final": keywordC, "const": keywordC, "abstract": keywordC, "static": keywordC,
|
||||
|
||||
"int": keywordC, "double": keywordC, "long": keywordC, "boolean": keywordC, "char": keywordC,
|
||||
"void": keywordC, "byte": keywordC, "float": keywordC, "short": keywordC
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
// Wrapper around javaToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function javaTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = javaToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(javaTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, inteded to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function javaToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "java-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "java-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "java-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "java-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "java-comment"};
|
||||
}
|
||||
|
||||
// for reading javadoc
|
||||
function readJavaDocComment(start){
|
||||
var newInside = "/**";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "javadoc", style: "javadoc-comment"};
|
||||
}
|
||||
// for reading annotations (word based)
|
||||
function readAnnotation(){
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
return {type: "annotation", style: "java-annotation", content:word};
|
||||
}
|
||||
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "java-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "java-string"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
else if(inside == "/**")
|
||||
return readJavaDocComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "java-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "@"){
|
||||
return readAnnotation();
|
||||
}else if (ch == "/"){
|
||||
if (source.equals("*")){
|
||||
source.next();
|
||||
|
||||
if(source.equals("*"))
|
||||
return readJavaDocComment(ch);
|
||||
|
||||
return readMultilineComment(ch);
|
||||
}
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "java-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || javaTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
@@ -1,32 +0,0 @@
|
||||
Copyright (c) 2009, Franciszek Wawrzak
|
||||
All rights reserved.
|
||||
|
||||
This software is provided for use in connection with the
|
||||
CodeMirror suite of modules and utilities, hosted and maintained
|
||||
at http://codemirror.net/.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,63 +0,0 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.lua-comment {
|
||||
color: #BB9977;
|
||||
}
|
||||
|
||||
span.lua-keyword {
|
||||
font-weight: bold;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.lua-string {
|
||||
color: #AA2222;
|
||||
}
|
||||
|
||||
span.lua-stdfunc {
|
||||
font-weight: bold;
|
||||
color: #077;
|
||||
}
|
||||
span.lua-customfunc {
|
||||
font-weight: bold;
|
||||
color: #0AA;
|
||||
}
|
||||
|
||||
|
||||
span.lua-identifier {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.lua-number {
|
||||
color: #3A3;
|
||||
}
|
||||
|
||||
span.lua-token {
|
||||
color: #151;
|
||||
}
|
||||
|
||||
span.lua-error {
|
||||
color: #FFF;
|
||||
background-color: #F00;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Lua demonstration</title>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s
|
||||
Lua parser. Written by <a href="http://francio.pl/">Franciszek
|
||||
Wawrzak</a>, released under a BSD-style <a
|
||||
href="LICENSE">license</a>.</p>
|
||||
|
||||
<div style="border: 1px solid black; padding: 0px;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
--[[
|
||||
example useless code to show lua syntax highlighting
|
||||
this is multiline comment
|
||||
]]
|
||||
|
||||
function blahblahblah(x)
|
||||
|
||||
local table = {
|
||||
"asd" = 123,
|
||||
"x" = 0.34,
|
||||
}
|
||||
if x ~= 3 then
|
||||
print( x )
|
||||
elseif x == "string"
|
||||
my_custom_function( 0x34 )
|
||||
else
|
||||
unknown_function( "some string" )
|
||||
end
|
||||
|
||||
--single line comment
|
||||
|
||||
end
|
||||
|
||||
function blablabla3()
|
||||
|
||||
for k,v in ipairs( table ) do
|
||||
--abcde..
|
||||
y=[=[
|
||||
x=[[
|
||||
x is a multi line string
|
||||
]]
|
||||
but its definition is iside a highest level string!
|
||||
]=]
|
||||
print(" \"\" ")
|
||||
--this marks a parser error:
|
||||
s = [== asdasdasd]]
|
||||
|
||||
s = math.sin( x )
|
||||
end
|
||||
|
||||
end
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "350px",
|
||||
parserfile: "../contrib/lua/js/parselua.js",
|
||||
stylesheet: "css/luacolors.css",
|
||||
path: "../../js/"
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
Simple parser for LUA
|
||||
Written for Lua 5.1, based on parsecss and other parsers.
|
||||
features: highlights keywords, strings, comments (no leveling supported! ("[==[")),tokens, basic indenting
|
||||
|
||||
to make this parser highlight your special functions pass table with this functions names to parserConfig argument of creator,
|
||||
|
||||
parserConfig: ["myfunction1","myfunction2"],
|
||||
*/
|
||||
|
||||
|
||||
function findFirstRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")", "i");
|
||||
}
|
||||
|
||||
function matchRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var luaCustomFunctions= matchRegexp([]);
|
||||
|
||||
function configureLUA(parserConfig){
|
||||
if(parserConfig)
|
||||
luaCustomFunctions= matchRegexp(parserConfig);
|
||||
}
|
||||
|
||||
|
||||
//long list of standard functions from lua manual
|
||||
var luaStdFunctions = matchRegexp([
|
||||
"_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load","loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require","select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
|
||||
|
||||
"coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
|
||||
|
||||
"debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable","debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable","debug.setupvalue","debug.traceback",
|
||||
|
||||
"close","flush","lines","read","seek","setvbuf","write",
|
||||
|
||||
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin","io.stdout","io.tmpfile","io.type","io.write",
|
||||
|
||||
"math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg","math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max","math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh","math.sqrt","math.tan","math.tanh",
|
||||
|
||||
"os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale","os.time","os.tmpname",
|
||||
|
||||
"package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload","package.seeall",
|
||||
|
||||
"string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub","string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
|
||||
|
||||
"table.concat","table.insert","table.maxn","table.remove","table.sort"
|
||||
]);
|
||||
|
||||
|
||||
|
||||
var luaKeywords = matchRegexp(["and","break","elseif","false","nil","not","or","return",
|
||||
"true","function", "end", "if", "then", "else", "do",
|
||||
"while", "repeat", "until", "for", "in", "local" ]);
|
||||
|
||||
var luaIndentKeys = matchRegexp(["function", "if","repeat","for","while", "[\(]", "{"]);
|
||||
var luaUnindentKeys = matchRegexp(["end", "until", "[\)]", "}"]);
|
||||
|
||||
var luaUnindentKeys2 = findFirstRegexp(["end", "until", "[\)]", "}"]);
|
||||
var luaMiddleKeys = findFirstRegexp(["else","elseif"]);
|
||||
|
||||
|
||||
|
||||
var LUAParser = Editor.Parser = (function() {
|
||||
var tokenizeLUA = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
|
||||
if (ch == "-" && source.equals("-")) {
|
||||
source.next();
|
||||
setState(inSLComment);
|
||||
return null;
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
setState(inString(ch));
|
||||
return null;
|
||||
}
|
||||
if (ch == "[" && (source.equals("[") || source.equals("="))) {
|
||||
var level = 0;
|
||||
while(source.equals("=")){
|
||||
level ++;
|
||||
source.next();
|
||||
}
|
||||
if(! source.equals("[") )
|
||||
return "lua-error";
|
||||
setState(inMLSomething(level,"lua-string"));
|
||||
return null;
|
||||
}
|
||||
|
||||
else if (ch == "=") {
|
||||
if (source.equals("="))
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (ch == ".") {
|
||||
if (source.equals("."))
|
||||
source.next();
|
||||
if (source.equals("."))
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (ch == "+" || ch == "-" || ch == "*" || ch == "/" || ch == "%" || ch == "^" || ch == "#" ) {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (ch == ">" || ch == "<" || ch == "(" || ch == ")" || ch == "{" || ch == "}" || ch == "[" ) {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (ch == "]" || ch == ";" || ch == ":" || ch == ",") {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (source.equals("=") && (ch == "~" || ch == "<" || ch == ">")) {
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (/\d/.test(ch)) {
|
||||
source.nextWhileMatches(/[\w.%]/);
|
||||
return "lua-number";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[\w\\\-_.]/);
|
||||
return "lua-identifier";
|
||||
}
|
||||
}
|
||||
|
||||
function inSLComment(source, setState) {
|
||||
var start = true;
|
||||
var count=0;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
var level = 0;
|
||||
if ((ch =="[") && start){
|
||||
while(source.equals("=")){
|
||||
source.next();
|
||||
level++;
|
||||
}
|
||||
if (source.equals("[")){
|
||||
setState(inMLSomething(level,"lua-comment"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
start = false;
|
||||
}
|
||||
setState(normal);
|
||||
return "lua-comment";
|
||||
|
||||
}
|
||||
|
||||
function inMLSomething(level,what) {
|
||||
//wat sholud be "lua-string" or "lua-comment", level is the number of "=" in opening mark.
|
||||
return function(source, setState){
|
||||
var dashes = 0;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (dashes == level+1 && ch == "]" ) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
if (dashes == 0)
|
||||
dashes = (ch == "]") ? 1:0;
|
||||
else
|
||||
dashes = (ch == "=") ? dashes + 1 : 0;
|
||||
}
|
||||
return what;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function inString(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped)
|
||||
break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped)
|
||||
setState(normal);
|
||||
return "lua-string";
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentLUA(indentDepth, base) {
|
||||
return function(nextChars) {
|
||||
|
||||
var closing = (luaUnindentKeys2.test(nextChars) || luaMiddleKeys.test(nextChars));
|
||||
|
||||
|
||||
return base + ( indentUnit * (indentDepth - (closing?1:0)) );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function parseLUA(source,basecolumn) {
|
||||
basecolumn = basecolumn || 0;
|
||||
|
||||
var tokens = tokenizeLUA(source);
|
||||
var indentDepth = 0;
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next(), style = token.style, content = token.content;
|
||||
|
||||
|
||||
|
||||
if (style == "lua-identifier" && luaKeywords.test(content)){
|
||||
token.style = "lua-keyword";
|
||||
}
|
||||
if (style == "lua-identifier" && luaStdFunctions.test(content)){
|
||||
token.style = "lua-stdfunc";
|
||||
}
|
||||
if (style == "lua-identifier" && luaCustomFunctions.test(content)){
|
||||
token.style = "lua-customfunc";
|
||||
}
|
||||
|
||||
if (luaIndentKeys.test(content))
|
||||
indentDepth++;
|
||||
else if (luaUnindentKeys.test(content))
|
||||
indentDepth--;
|
||||
|
||||
|
||||
if (content == "\n")
|
||||
token.indentation = indentLUA( indentDepth, basecolumn);
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _tokenState = tokens.state, _indentDepth = indentDepth;
|
||||
return function(source) {
|
||||
tokens = tokenizeLUA(source, _tokenState);
|
||||
|
||||
indentDepth = _indentDepth;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parseLUA, configure:configureLUA, electricChars: "delf})"}; //en[d] els[e] unti[l] elsei[f] // this should be taken from Keys keywords
|
||||
})();
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
Copyright (c) 2007-2009 Marijn Haverbeke
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Marijn Haverbeke
|
||||
marijnh at gmail
|
||||
@@ -1,63 +0,0 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.js-punctuation {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.js-operator {
|
||||
color: #E1570F;
|
||||
}
|
||||
|
||||
span.js-keyword {
|
||||
color: #770088;
|
||||
}
|
||||
|
||||
span.js-atom {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
span.js-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-variabledef {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.js-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.js-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.js-string {
|
||||
color: #AA2222;
|
||||
}
|
||||
|
||||
span.ometa-binding {
|
||||
color: #FF0000;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: OmetaJS demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s <a
|
||||
href="http://www.tinlizzie.org/ometa">OmetaJS</a> parser.</p>
|
||||
|
||||
<p>Adapted from the official Javascript parser by Eric KEDJI
|
||||
<<a href="mailto:eric.kedji@gmail.com">eric.kedji@gmail.com</a>>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
// Source: http://www.tinlizzie.org/ometa-js/#Lisp
|
||||
// Inspired by McCarthy's meta-circular lisp
|
||||
|
||||
ometa Lisp {
|
||||
ev = string:a -> self.env[a]
|
||||
| [#lambda :fs :body] -> [#lambda, fs, body]
|
||||
| [#quote :ans] -> ans
|
||||
| [#cond evCond:ans] -> ans
|
||||
| [ev:f ev*:xs] app(f, xs):ans -> ans,
|
||||
|
||||
evCond = condF* condT:ans anything* -> x,
|
||||
condT = [ev:x ?x ev:ans] -> ans,
|
||||
condF = ~condT anything,
|
||||
|
||||
app = #car [[:hd anything*]] -> hd
|
||||
| #cdr [[:hd anything*:tl]] -> tl
|
||||
| #cons [:hd :tl] -> [hd].concat(tl)
|
||||
| #atom [:x] -> (!(x instanceof Array))
|
||||
| #eq [:x :y] -> (x == y)
|
||||
| [#lambda :fs :body] :args
|
||||
enter bind(fs, args) ev(body):ans leave -> ans,
|
||||
enter = -> (self.env = self.env.delegated({_p: self.env})),
|
||||
bind = [] []
|
||||
| [:f anything*:fs] [:a anything*:as] bind(fs, as) -> (self.env[f] = a),
|
||||
leave = -> (self.env = self.env._p)
|
||||
}
|
||||
Lisp.initialize = function() { this.env = {car: "car", cdr: "cdr", cons: "cons", atom: "atom", eq: "eq", nil: null, T: "T"} }
|
||||
lispEval = function(x) { return Lisp.match(x, "ev") }
|
||||
|
||||
lispEval([`quote, [1, 2, 3]])
|
||||
lispEval([`car, [`quote, [1, 2, 3]]])
|
||||
lispEval([`cdr, [`quote, [1, 2, 3]]])
|
||||
lispEval([`cons, [`quote, `x], [`quote, `y]])
|
||||
lispEval([`eq, [`quote, `x], [`quote, `x]])
|
||||
lispEval([[`lambda, [`x], [`cons, `x, `x]], [`quote, `boo]])
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
/* var textarea = document.getElementById('code');
|
||||
var editor = new MirrorFrame(CodeMirror.replace(textarea), {
|
||||
height: "350px",
|
||||
content: textarea.value,
|
||||
parserfile: ["tokenizeometa.js", "parseometa.js"],
|
||||
stylesheet: "css/ometacolors.css",
|
||||
path: "js/",
|
||||
autoMatchParens: true
|
||||
});
|
||||
*/
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: ["../contrib/ometa/js/tokenizeometa.js",
|
||||
"../contrib/ometa/js/parseometa.js"],
|
||||
stylesheet: "css/ometacolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,209 +0,0 @@
|
||||
/* Tokenizer for JavaScript code */
|
||||
|
||||
var tokenizeJavaScript = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "js-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
||||
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
||||
"ometa": keywordB
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|~]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
|
||||
// Wrapper around jsToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function jsTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(jsTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, intended to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function jsToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "js-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "js-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "js-comment"};
|
||||
}
|
||||
function readMultilineString(start, quotes) {
|
||||
var newInside = quotes;
|
||||
var quote = quotes.charAt(0);
|
||||
var maybeEnd = (start == quote);
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == quote && source.peek() == quote && maybeEnd) {
|
||||
source.next();
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == quote);
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "multilineString", style: "js-string"};
|
||||
}
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "js-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "js-string"};
|
||||
}
|
||||
function readOmetaIdentifierString() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
return {type: "string", style: "js-string"};
|
||||
}
|
||||
function readOmetaBinding() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
return {type: "variable", style: "ometa-binding"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
if (inside == '"""' || inside == "'''")
|
||||
return readMultilineString(ch, inside);
|
||||
if (ch == '"' && source.lookAhead('""', true) || ch == "'" && source.lookAhead("''", true))
|
||||
return readMultilineString('-', ch+ch+ch); // work as far as '-' is not '"' nor "'"
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
else if (ch == "`" || ch == "#" )
|
||||
return readOmetaIdentifierString();
|
||||
else if (ch == ':' && isWordChar.test(source.peek()))
|
||||
return readOmetaBinding();
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "js-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "/"){
|
||||
if (source.equals("*"))
|
||||
{ source.next(); return readMultilineComment(ch); }
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || jsTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
@@ -1,37 +0,0 @@
|
||||
Copyright (c) 2008-2009, Yahoo! Inc.
|
||||
All rights reserved.
|
||||
|
||||
This software is provided for use in connection with the
|
||||
CodeMirror suite of modules and utilities, hosted and maintained
|
||||
at http://codemirror.net/.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of Yahoo! Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of Yahoo! Inc.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
*/
|
||||
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
/*We should define specific styles for every element of the syntax.
|
||||
the setting below will cause some annoying color to show through if we missed
|
||||
defining a style for a token. This is also the "color" of the whitespace and
|
||||
of the cursor.
|
||||
*/
|
||||
pre.code, .editbox {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.php-punctuation {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.php-keyword {
|
||||
color: #770088;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.php-operator {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
/* __FILE__ etc.; http://php.net/manual/en/reserved.php */
|
||||
span.php-compile-time-constant {
|
||||
color: #776088;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* output of get_defined_constants(). Differs from http://php.net/manual/en/reserved.constants.php */
|
||||
span.php-predefined-constant {
|
||||
color: darkgreen;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* PHP reserved "language constructs"... echo() etc.; http://php.net/manual/en/reserved.php */
|
||||
span.php-reserved-language-construct {
|
||||
color: green;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* PHP built-in functions: glob(), chr() etc.; output of get_defined_functions()["internal"] */
|
||||
span.php-predefined-function {
|
||||
color: green;
|
||||
}
|
||||
|
||||
/* PHP predefined classes: PDO, Exception etc.; output of get_declared_classes() and different from http://php.net/manual/en/reserved.classes.php */
|
||||
span.php-predefined-class {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.php-atom {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
/* class, interface, namespace or function names, but not $variables */
|
||||
span.php-t_string {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.php-variable {
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
span.js-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.php-comment {
|
||||
color: #AA7700;
|
||||
font-stretch: condensed;
|
||||
/* font-style: italic; This causes line height to slightly change, getting line numbers out of sync */
|
||||
}
|
||||
|
||||
span.php-string-single-quoted {
|
||||
color: #AA2222;
|
||||
}
|
||||
/* double quoted strings allow interpolation */
|
||||
span.php-string-double-quoted {
|
||||
color: #AA2222;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.syntax-error {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
span.deprecated {
|
||||
font-size: smaller;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
|
||||
Based on parsehtmlmixed.js by Marijn Haverbeke.
|
||||
*/
|
||||
|
||||
var PHPHTMLMixedParser = Editor.Parser = (function() {
|
||||
var processingInstructions = ["<?php"];
|
||||
|
||||
if (!(PHPParser && CSSParser && JSParser && XMLParser))
|
||||
throw new Error("PHP, CSS, JS, and XML parsers must be loaded for PHP+HTML mixed mode to work.");
|
||||
XMLParser.configure({useHTMLKludges: true});
|
||||
|
||||
function parseMixed(stream) {
|
||||
var htmlParser = XMLParser.make(stream), localParser = null,
|
||||
inTag = false, lastAtt = null, phpParserState = null;
|
||||
var iter = {next: top, copy: copy};
|
||||
if (Editor.Parser.options && Editor.Parser.options.parserConfig.phpOnly == true)
|
||||
iter.next = local(PHPParser, "?>");
|
||||
|
||||
function top() {
|
||||
var token = htmlParser.next();
|
||||
if (token.content == "<")
|
||||
inTag = true;
|
||||
else if (token.style == "xml-tagname" && inTag === true)
|
||||
inTag = token.content.toLowerCase();
|
||||
else if (token.style == "xml-attname")
|
||||
lastAtt = token.content;
|
||||
else if (token.type == "xml-processing") {
|
||||
// see if this opens a PHP block
|
||||
for (var i = 0; i < processingInstructions.length; i++)
|
||||
if (processingInstructions[i] == token.content) {
|
||||
iter.next = local(PHPParser, "?>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (token.style == "xml-attribute" && token.content == "\"php\"" && inTag == "script" && lastAtt == "language")
|
||||
inTag = "script/php";
|
||||
// "xml-processing" tokens are ignored, because they should be handled by a specific local parser
|
||||
else if (token.content == ">") {
|
||||
if (inTag == "script/php")
|
||||
iter.next = local(PHPParser, "</script>");
|
||||
else if (inTag == "script")
|
||||
iter.next = local(JSParser, "</script");
|
||||
else if (inTag == "style")
|
||||
iter.next = local(CSSParser, "</style");
|
||||
lastAtt = null;
|
||||
inTag = false;
|
||||
}
|
||||
else if (token.type == "xml-text" && token.style == "xml-text") {
|
||||
if (Editor.Parser.options && Editor.Parser.options.parserConfig.phpOnly == true)
|
||||
iter.next = local(PHPParser, "?>");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
function local(parser, tag) {
|
||||
var baseIndent = htmlParser.indentation();
|
||||
if (parser == PHPParser && phpParserState)
|
||||
localParser = phpParserState(stream);
|
||||
else
|
||||
localParser = parser.make(stream, baseIndent + indentUnit);
|
||||
|
||||
return function() {
|
||||
if (stream.lookAhead(tag, false, false, true)) {
|
||||
if (parser == PHPParser) phpParserState = localParser.copy();
|
||||
localParser = null;
|
||||
iter.next = top;
|
||||
return top(); // pass the ending tag to the enclosing parser
|
||||
}
|
||||
|
||||
var token = localParser.next();
|
||||
var lt = token.value.lastIndexOf("<"), sz = Math.min(token.value.length - lt, tag.length);
|
||||
if (lt != -1 && token.value.slice(lt, lt + sz).toLowerCase() == tag.slice(0, sz) &&
|
||||
stream.lookAhead(tag.slice(sz), false, false, true)) {
|
||||
stream.push(token.value.slice(lt));
|
||||
token.value = token.value.slice(0, lt);
|
||||
}
|
||||
|
||||
if (token.indentation) {
|
||||
var oldIndent = token.indentation;
|
||||
token.indentation = function(chars) {
|
||||
if (chars == "</")
|
||||
return baseIndent;
|
||||
else
|
||||
return oldIndent(chars);
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
};
|
||||
}
|
||||
|
||||
function copy() {
|
||||
var _html = htmlParser.copy(), _local = localParser && localParser.copy(),
|
||||
_next = iter.next, _inTag = inTag, _lastAtt = lastAtt, _php = phpParserState;
|
||||
return function(_stream) {
|
||||
stream = _stream;
|
||||
htmlParser = _html(_stream);
|
||||
localParser = _local && _local(_stream);
|
||||
phpParserState = _php;
|
||||
iter.next = _next;
|
||||
inTag = _inTag;
|
||||
lastAtt = _lastAtt;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseMixed,
|
||||
electricChars: "{}/:",
|
||||
configure: function(conf) {
|
||||
if (conf.opening != null) processingInstructions = conf.opening;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,22 +0,0 @@
|
||||
Copyright (c) 2010 Peter Raganitsch
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Peter Raganitsch
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user