Permalink
Browse files

went back and continued working on the mixed mode parser because the …

…standard html parser is not flexible enough.
  • Loading branch information...
1 parent 92095f6 commit 1b635507629c5e9785c821b61f446451ad2c72a5 @tobi committed Nov 8, 2009
View
@@ -128,12 +128,11 @@
</style>
<script type="text/javascript">
- var editor = CodeMirror.fromTextArea('code', {
+ CodeMirror.fromTextArea('code', {
height: "600px",
- parserfile: "../../javascripts/parseliquid.js",
- stylesheet: "/stylesheets/liquidcolors.css",
+ parserfile: "../../javascripts/parseliquid.js" ,
+ stylesheet: ["/codemirror/css/xmlcolors.css", "/stylesheets/liquidcolors.css"],
path: "codemirror/js/",
- continuousScanning: 500,
textWrapping: false,
lineNumbers: true
});
@@ -6,7 +6,7 @@
* {useHTMLKludges: false} as parserConfig option.
*/
-var XMLParser = Editor.Parser = (function() {
+var LiquidParser = Editor.Parser = (function() {
var Kludges = {
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
"meta": true, "col": true, "frame": true, "base": true, "area": true},
@@ -15,6 +15,16 @@ var XMLParser = Editor.Parser = (function() {
var NoKludges = {autoSelfClosers: {}, doNotIndent: {"!cdata": true}};
var UseKludges = Kludges;
var alignCDATA = false;
+
+ var isQuote = /[\'\"]/;
+ var isWordChar = /[\w\_]/
+ var isPunctuation = /[\.\|\=\:]/;
+
+ var keywords = {};
+
+ ['in'].forEach(function(element, index, array) {
+ keywords[element] = true;
+ });
// Simple stateful tokenizer for XML documents. Returns a
// MochiKit-style iterator, with a state property that contains a
@@ -62,7 +72,7 @@ var XMLParser = Editor.Parser = (function() {
}
if (source.equals("%")) {
source.next();
- setState(inLiquidTag);
+ setState(inLiquidTagName);
return 'liquid-punctuation';
}
else {
@@ -109,44 +119,63 @@ var XMLParser = Editor.Parser = (function() {
function inLiquidOutput(source, setState) {
var ch = source.next();
if (ch == "}") {
- if (source.equals('}')) {
- source.next()
+ if(source.equals("}")) {
+ source.next();
setState(inText);
return "liquid-punctuation";
+ }
+ else {
+ setState(inText);
+ return "liquid-bad-punctuation";
}
}
- else if (/[\'\"]/.test(ch)) {
+ else if (isQuote.test(ch)) {
setState(inLiquidString(ch, inLiquidOutput));
return null;
}
- else if (/[\|\=\:]/.test(ch)) {
+ else if (isPunctuation.test(ch)) {
return "liquid-punctuation";
}
- else {
- source.nextWhileMatches(/[\s\n]/);
- return "liquid-text";
- }
+
+ return "liquid-text";
+ }
+
+ function inLiquidTagName(source, setState) {
+ source.nextWhileMatches(isWordChar);
+ setState(inLiquidTag);
+ return "liquid-tag-name";
}
function inLiquidTag(source, setState) {
var ch = source.next();
if (ch == "%") {
- if (source.equals('}')) {
- source.next()
+ if(source.equals("}")) {
+ source.next();
setState(inText);
return "liquid-punctuation";
}
}
- else if (/[\'\"]/.test(ch)) {
+ else if (isQuote.test(ch)) {
setState(inLiquidString(ch, inLiquidTag));
return null;
}
- else if (/[\|\=\:]/.test(ch)) {
+ else if (isPunctuation.test(ch)) {
return "liquid-punctuation";
}
+ else {
+ return readWord(source, keywords)
+ }
+ }
+
+ function readWord(source, keywords) {
+ source.nextWhileMatches(isWordChar);
+ var word = source.get();
+
+ if (keywords && keywords.propertyIsEnumerable(word)) {
+ return {type: "string", style: "liquid-keyword", content: word};
+ }
else {
- source.nextWhileMatches(/ \n/);
- return "liquid-text";
+ return {type: "string", style: "liquid-text", content: word};
}
}
@@ -255,7 +284,7 @@ var XMLParser = Editor.Parser = (function() {
return pass(element, base);
}
var harmlessTokens = {"xml-text": true, "xml-entity": true, "xml-comment": true, "xml-processing": true};
- var liquidTokens = {"liquid-punctuation": true, "liquid-variable": true, "liquid-text": true, "liquid-string": true};
+ var liquidTokens = {"liquid-punctuation": true, "liquid-bad-punctuation": true, "liquid-keyword": true, "liquid-tag-name": true, "liquid-variable": true, "liquid-text": true, "liquid-string": true};
function element(style, content) {
if (content == "<") cont(tagname, attributes, endtag(tokenNr == 1));
else if (content == "</") cont(closetagname, expect(">"));
@@ -289,6 +318,16 @@ var XMLParser = Editor.Parser = (function() {
}
cont();
}
+ function closeliquidtagname(style, content) {
+ if (style == "liquid-tag-name" && context && content.toLowerCase() == context.name) {
+ popContext();
+ mark("xml-tagname");
+ }
+ else {
+ mark("xml-error");
+ }
+ cont();
+ }
function endtag(startOfLine) {
return function(style, content) {
if (content == "/>" || (content == ">" && UseKludges.autoSelfClosers.hasOwnProperty(currentTag))) cont();
@@ -16,11 +16,10 @@ if (!Array.prototype.forEach)
}
-var LiquidParser = Editor.Parser = (function() {
-
- var isPunctuation = /[\.\|\=\:\[\]]/;
+var LiquidParser = Editor.Parser =(function() {
var isQuote = /[\'\"]/;
var isWordChar = /[\w\_]/
+ var isPunctuation = /[\.\|\=\:\[\]]/;
var keywords = {};
View
@@ -60,7 +60,7 @@
<script type="text/javascript">
var editor = CodeMirror.fromTextArea('code', {
height: "600px",
- parserfile: "../../javascripts/parseliquid2.js",
+ parserfile: ["../../javascripts/parseliquid2.js", "../../javascripts/mixed.js"],
stylesheet: "/stylesheets/liquidcolors.css",
path: "codemirror/js/",
//continuousScanning: 500,
@@ -1,83 +1,36 @@
-.editbox {
- margin: .4em;
- padding: 0;
- font-family: monospace;
- font-size: 10pt;
- color: black;
-}
-
-.editbox p {
- margin: 0;
-}
-
-span.xml-tagname {
- color: #A0B;
-}
-
-span.xml-attribute {
- color: #281;
-}
-
-span.xml-punctuation {
- color: black;
-}
-
-span.xml-attname {
- color: #00F;
-}
-
-span.xml-comment {
- color: #A70;
-}
-
-span.xml-cdata {
- color: #48A;
-}
-span.xml-processing {
- color: #999;
-}
-
-span.xml-entity {
- color: #A22;
-}
-
-span.xml-error {
- color: #F00;
-}
-
-span.xml-text {
- color: black;
+span.liquid-punctuation {
+ color: silver;
}
-span.liquid-punctuation {
- color: pink;
- background-color: #eee;
+span.liquid-bad-punctuation {
+ color: red;
+ text-decoration: underline;
}
span.liquid-text {
- color: purple;
- background-color: #eee;
+ color: black;
}
span.liquid-variable {
color: magenta;
- background-color: #eee;
}
span.liquid-string {
color: green;
- background-color: #eee;
}
span.liquid-tag-name {
color: green;
font-weight: bold;
- background-color: #eee;
}
span.liquid-keyword {
- color: green;
+ color: black;
+ font-weight: bold;
+}
+
+span.liquid-tag-name {
+ color: black;
font-weight: bold;
- background-color: #eee;
}

0 comments on commit 1b63550

Please sign in to comment.