Verified Commit 8868b450 authored by Camil Staps's avatar Camil Staps 🙂

Better scope tracking; add full (dcl) module test case (for now without imports)

parent 581225cd
......@@ -24,9 +24,16 @@ function highlight(lex, istr, start) {
for (var i in lex[state]) {
var patt = lex[state][i][0];
var clss = lex[state][i][1];
var new_states = lex[state][i].length > 2 ? lex[state][i][2] : null;
if (istr.match(patt)) {
var parts = patt.exec(istr);
var j = 0;
if (typeof clss == 'function') {
var result = clss(parts);
clss = result[0];
if (result.length > 1)
new_states = result[1];
}
for (var k in clss) {
j++;
if (out.length > 0 && out[out.length-1]['class'] == clss[k])
......@@ -37,8 +44,7 @@ function highlight(lex, istr, start) {
istr = parts[j+1];
found = true;
if (lex[state][i].length > 2) {
var new_states = lex[state][i][2];
if (new_states != null) {
new_states = new_states.split(';');
for (var i in new_states) {
var new_state = new_states[i];
......@@ -93,8 +99,12 @@ function highlightClean(func, callback, start) {
var myCallback = function(span, cls, str) {
if (cls == '__type__')
return highlightClean(str, callback);
if (cls == 'argument')
else if (cls == '__reset__arguments__') {
macroargs = [];
return callback(
span.replace('class="' + cls + '"', 'class="whitespace"'),
'whitespace', str);
} else if (cls == 'argument')
macroargs.push(str);
else if (macroargs.indexOf(str) >= 0)
return callback(
......@@ -107,17 +117,38 @@ function highlightClean(func, callback, start) {
return span;
};
var indent = 0;
var i = 0;
return highlightToHTML({
_prepend: [
[/(\/\/.*)/, ['comment']],
[/(\/\*)/, ['comment'], 'comment'],
],
_append: [
[/(\n[^\n\S]*)/, function(matches) {
var whitespace = matches[1];
var rest = matches[2];
var old_indent = indent;
indent = whitespace.substring(1).replace('\t',' ').length;
if (indent < old_indent || indent == 0) {
var cls = 'whitespace';
if (!rest.match(/^[\s\n]*where/))
cls = '__reset__arguments__';
return [[cls], 'reset:start'];
} else {
return [['whitespace']];
}
}],
[/([^\n\S]+)/, ['whitespace']],
[/(\n(?=\S))/, ['whitespace'], 'reset:start'],
[/(\n)/, ['whitespace']],
[/(.+)/, ['error']]
],
comment: [
[/([^*\\]+)/, ['comment']],
[/(\*\/)/, ['comment'], 'pop'],
[/(\/\*)/, ['comment'], 'comment'],
[/(\*|\\)/, ['comment']]
],
start: [
[/(generic)(\s)/,
['keyword', 'whitespace'], 'generic'],
......@@ -145,19 +176,11 @@ function highlightClean(func, callback, start) {
[/([^\(\)\s]+)/, ['funcname'], 'funcargs']
],
funcargs: [
[/(\n)(?=[^\s\/])/, ['whitespace'], 'start'],
[/(\s)/, ['whitespace']],
[/((?::=)?=)/, ['punctuation'], 'jump:rhs'],
[/([:\[\](),]+)/, ['punctuation']],
[/(\|)/, ['punctuation'], 'jump:guard'],
[/([^:\[\](),\s]+)/, ['argument']]
],
comment: [
[/([^*\\]+)/, ['comment']],
[/(\*\/)/, ['comment'], 'pop'],
[/(\/\*)/, ['comment'], 'comment'],
[/(\*|\\)/, ['comment']]
],
startConstructor: [ // alternative entry point in case this is a constructor
[/(.*)(infix[lr]?)(\s*)(\d*)(\s*)(::)/,
['constructor', 'keyword', 'whitespace', 'keyword',
......@@ -180,7 +203,6 @@ function highlightClean(func, callback, start) {
],
type: [
[/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']],
[/(where)/, ['keyword'], 'pop'],
[/([a-z][\w`]*)/, ['typevar']],
[/(A)(\.)/, ['existential', 'punctuation'], 'quantifiedVariables'],
......@@ -259,7 +281,7 @@ function highlightClean(func, callback, start) {
],
rhs: [
[/(\n)(\|)/, ['whitespace', 'punctuation'], 'jump:guard'],
[/(\n)/, ['whitespace'], 'pop'],
[/(\n[^\n\S]+)/, ['whitespace'], 'pop'],
[/(code\s+(?:inline\s*)?)({)/,
['keyword', 'punctuation'], 'abc'],
[/\b(if|let|in|with|case|of|otherwise)\b/,
......
......@@ -24,7 +24,8 @@ whitespace
typevar m
whitespace
keyword where
whitespace \n\n
whitespace \n
whitespace \n
funcname bind
whitespace
punctuation ::
......
......@@ -29,7 +29,8 @@ whitespace
typevar s
whitespace
keyword where
whitespace \n\n
whitespace \n
whitespace \n
funcname textSize
whitespace
punctuation ::
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment