Verified Commit fa821597 authored by Camil Staps's avatar Camil Staps
Browse files

Greatly improve ABC highlighting; restructure "macro" (any function implementation)

parent d5f9ecb1
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
font-weight: bold; font-weight: bold;
} }
.funcname.funcname-onlyused, .macroargument { .funcname.funcname-onlyused, .argument {
color: #6e94ad; color: #6e94ad;
font-weight: normal; font-weight: normal;
} }
.macroargumentinrhs { .argumentinrhs {
color: #888; color: #888;
} }
...@@ -56,3 +56,16 @@ ...@@ -56,3 +56,16 @@
.literal { .literal {
color: #a42e30; color: #a42e30;
} }
.abc-instruction {
color: #087c35;
font-weight: bold;
}
.abc-directive {
color: #a42e30;
}
.abc-argument {
font-style: italic;
}
...@@ -87,12 +87,12 @@ function highlightFunction(func, callback, start) { ...@@ -87,12 +87,12 @@ function highlightFunction(func, callback, start) {
if (cls == '__type__') if (cls == '__type__')
return highlightFunction(str, callback); return highlightFunction(str, callback);
if (cls == 'macroargument') if (cls == 'argument')
macroargs.push(str); macroargs.push(str);
else if (macroargs.indexOf(str) >= 0) else if (macroargs.indexOf(str) >= 0)
return callback( return callback(
span.replace('class="' + cls + '"', 'class="macroargumentinrhs"'), span.replace('class="' + cls + '"', 'class="argumentinrhs"'),
'macroargumentinrhs', str); 'argumentinrhs', str);
if (typeof callback == 'function') if (typeof callback == 'function')
return callback(span, cls, str); return callback(span, cls, str);
...@@ -122,11 +122,25 @@ function highlightFunction(func, callback, start) { ...@@ -122,11 +122,25 @@ function highlightFunction(func, callback, start) {
[/(foreign export(?: (?:c|std)call)?)/, [/(foreign export(?: (?:c|std)call)?)/,
['keyword']], ['keyword']],
[/(\/\/.*)/, ['comment']], [/(\/\/.*)/, ['comment']],
[/(\/\*)/, ['comment'], 'comment'],
[/([\(\)])/, ['punctuation']], [/([\(\)])/, ['punctuation']],
[/(::)/, ['punctuation'], 'type'], [/(::)/, ['punctuation'], 'type'],
[/(=>)/, ['punctuation']], [/(=>)/, ['punctuation']],
[/(")/, ['literal literal-string'], 'string'], [/(")/, ['literal literal-string'], 'string'],
[/([^\(\)\s]+)/, ['funcname']] [/([^\(\)\s]+)/, ['funcname'], 'funcargs']
],
funcargs: [
[/(\s+)/, ['whitespace']],
[/((?::=)?=)/, ['punctuation'], 'pop;rhs'],
[/([:\[\](),]+)/, ['punctuation']],
[/(\|)/, ['punctuation'], 'pop;guard'],
[/([^:\[\](),\s]+)/, ['argument']]
],
comment: [
[/([^*\\]+)/, ['comment']],
[/(\*\/)/, ['comment'], 'pop'],
[/(\/\*)/, ['comment'], 'comment'],
[/(\*|\\)/, ['comment']]
], ],
startConstructor: [ // alternative entry point in case this is a constructor startConstructor: [ // alternative entry point in case this is a constructor
[/(\s+)/, ['whitespace']], [/(\s+)/, ['whitespace']],
...@@ -215,18 +229,11 @@ function highlightFunction(func, callback, start) { ...@@ -215,18 +229,11 @@ function highlightFunction(func, callback, start) {
['__type__']], ['__type__']],
[/\b(where|with)\b/, ['keyword'], 'pop;macro'], [/\b(where|with)\b/, ['keyword'], 'pop;macro'],
[/(special)(\s)/,['keyword', 'whitespace'], 'special'], [/(special)(\s)/,['keyword', 'whitespace'], 'special'],
[/(\()(\S+)(\))/, ['punctuation', 'funcname', 'punctuation'], 'macroargs'], [/(\()(\S+)(\))/, ['punctuation', 'funcname', 'punctuation'], 'funcargs'],
[/(\S+)/, ['funcname'], 'macroargs'] [/(\S+)/, ['funcname'], 'funcargs']
], ],
macroargs: [ guard: [
[/(\s+)/, ['whitespace']], [/((?:^|\s)= )/, ['punctuation'], 'pop;rhs'],
[/((?::=)?=)/, ['punctuation'], 'pop;macrorhs'],
[/([:\[\](),]+)/, ['punctuation']],
[/(\|)/, ['punctuation'], 'pop;macroguard'],
[/([^:\[\](),\s]+)/, ['macroargument']]
],
macroguard: [
[/((?:^|\s)= )/, ['punctuation'], 'pop;macrorhs'],
[/(\s+)/, ['whitespace']], [/(\s+)/, ['whitespace']],
[/(otherwise)/, ['keyword']], [/(otherwise)/, ['keyword']],
[/('(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))')/, [/('(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))')/,
...@@ -247,8 +254,8 @@ function highlightFunction(func, callback, start) { ...@@ -247,8 +254,8 @@ function highlightFunction(func, callback, start) {
[/([\w`]+)/, ['funcname funcname-onlyused']], [/([\w`]+)/, ['funcname funcname-onlyused']],
[/(.)/, ['punctuation']] [/(.)/, ['punctuation']]
], ],
macrorhs: [ rhs: [
[/(\n)(\|)/, ['whitespace', 'punctuation'], 'pop;macroguard'], [/(\n)(\|)/, ['whitespace', 'punctuation'], 'pop;guard'],
[/(\n)/, ['whitespace'], 'pop'], [/(\n)/, ['whitespace'], 'pop'],
[/(\s+)/, ['whitespace']], [/(\s+)/, ['whitespace']],
[/(\/\/.*)/, ['comment']], [/(\/\/.*)/, ['comment']],
...@@ -299,6 +306,7 @@ function highlightFunction(func, callback, start) { ...@@ -299,6 +306,7 @@ function highlightFunction(func, callback, start) {
], ],
classHeading: [ classHeading: [
[/(\/\/.*)/, ['comment']], [/(\/\/.*)/, ['comment']],
[/(\s+)(where)/, ['whitespace', 'keyword']],
[/(\n)/, ['whitespace'], 'pop'], [/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']], [/(\s)/, ['whitespace']],
[/(class)/, ['keyword'], 'className'], [/(class)/, ['keyword'], 'className'],
...@@ -331,13 +339,40 @@ function highlightFunction(func, callback, start) { ...@@ -331,13 +339,40 @@ function highlightFunction(func, callback, start) {
[/(\S+)/, ['generic'], 'type'], [/(\S+)/, ['generic'], 'type'],
], ],
abc: [ abc: [
[/(\s+)/, ['whitespace']], [/(\.)/, ['abc-directive'], 'abcDirective'],
[/(\|.*)/, ['comment']], [/(\s+)/, ['whitespace'], 'abcInstruction'],
[/(\|.*\n)/, ['comment']],
[/(})/, ['punctuation'], 'pop'], [/(})/, ['punctuation'], 'pop'],
[/(")/, ['literal literal-string'], 'string'], [/(\S+)/, ['label'], 'abcInstruction']
],
abcInstruction: [
[/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']],
[/(\|.*\n)/, ['comment'], 'pop'],
[/(\S+)/, ['abc-instruction'], 'pop;abcArgument']
],
abcArgument: [
[/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']],
[/(\|.*\n)/, ['comment'], 'pop'],
[/('(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))')/,
['literal literal-char']],
[/\b([+~-]?\d+)\b/, [/\b([+~-]?\d+)\b/,
['literal literal-int literal-int-dec']], ['literal literal-int literal-int-dec']],
[/(\S+)/, ['funcname']], [/\b([+~-]?0x[\da-fA-F]+)\b/,
['literal literal-int literal-int-hex']],
[/\b([+~-]?\d+\.\d+(E[+-]?\d+)?)\b/,
['literal literal-real']],
[/\b(TRUE|FALSE)\b/,
['literal literal-bool']],
[/(")/, ['literal literal-string'], 'string'],
[/(\S+)/, ['abc-argument']]
],
abcDirective: [
[/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']],
[/(\|.*\n)/, ['comment'], 'pop'],
[/(\S+)/, ['abc-directive'], 'pop;abcArgument']
] ]
}, func, myCallback, start); }, func, myCallback, start);
} }
......
...@@ -94,17 +94,17 @@ punctuation ( ...@@ -94,17 +94,17 @@ punctuation (
funcname >>= funcname >>=
punctuation ) punctuation )
whitespace whitespace
macroargument ma argument ma
whitespace whitespace
macroargument a2mb argument a2mb
whitespace whitespace
punctuation :== punctuation :==
whitespace whitespace
funcname funcname-onlyused bind funcname funcname-onlyused bind
whitespace whitespace
macroargumentinrhs ma argumentinrhs ma
whitespace whitespace
macroargumentinrhs a2mb argumentinrhs a2mb
whitespace \n whitespace \n
punctuation ( punctuation (
funcname `b` funcname `b`
...@@ -148,17 +148,17 @@ punctuation ( ...@@ -148,17 +148,17 @@ punctuation (
funcname `b` funcname `b`
punctuation ) punctuation )
whitespace whitespace
macroargument ma argument ma
whitespace whitespace
macroargument a2mb argument a2mb
whitespace whitespace
punctuation :== punctuation :==
whitespace whitespace
funcname funcname-onlyused bind funcname funcname-onlyused bind
whitespace whitespace
macroargumentinrhs ma argumentinrhs ma
whitespace whitespace
macroargumentinrhs a2mb argumentinrhs a2mb
whitespace \n whitespace \n
punctuation ( punctuation (
funcname >>| funcname >>|
...@@ -198,13 +198,13 @@ punctuation ( ...@@ -198,13 +198,13 @@ punctuation (
funcname >>| funcname >>|
punctuation ) punctuation )
whitespace whitespace
macroargument ma argument ma
whitespace whitespace
macroargument mb argument mb
whitespace whitespace
punctuation :== punctuation :==
whitespace whitespace
macroargumentinrhs ma argumentinrhs ma
whitespace whitespace
punctuation >>= punctuation >>=
whitespace whitespace
...@@ -213,7 +213,7 @@ argument argument-wildcard _ ...@@ -213,7 +213,7 @@ argument argument-wildcard _
whitespace whitespace
punctuation -> punctuation ->
whitespace whitespace
macroargumentinrhs mb argumentinrhs mb
punctuation ) punctuation )
whitespace \n whitespace \n
punctuation ( punctuation (
...@@ -258,14 +258,14 @@ punctuation ( ...@@ -258,14 +258,14 @@ punctuation (
funcname =<< funcname =<<
punctuation ) punctuation )
whitespace whitespace
macroargument f argument f
whitespace whitespace
macroargument x argument x
whitespace whitespace
punctuation :== punctuation :==
whitespace whitespace
macroargumentinrhs x argumentinrhs x
whitespace whitespace
punctuation >>= punctuation >>=
whitespace whitespace
macroargumentinrhs f argumentinrhs f
Function
-----
class Text s // multiple members
where
textSize :: !s -> Int
concat :: ![s] -> s
-----
keyword class
whitespace
classname Text
whitespace
typevar s
whitespace
comment // multiple members
whitespace \n
keyword where
whitespace \n
funcname textSize
whitespace
punctuation ::
whitespace
punctuation !
typevar s
whitespace
punctuation ->
whitespace
type Int
whitespace \n
funcname concat
whitespace
punctuation ::
whitespace
punctuation ![
typevar s
punctuation ]
whitespace
punctuation ->
whitespace
typevar s
Function
-----
sleep :: !Int !*World -> *(!Int, !*World) // Linking with C
sleep n w = code {
ccall sleep "I:I:A"
}
-----
funcname sleep
whitespace
punctuation ::
whitespace
punctuation !
type Int
whitespace
punctuation !*
type World
whitespace
punctuation ->
whitespace
punctuation *(!
type Int
punctuation ,
whitespace
punctuation !*
type World
punctuation )
whitespace
comment // Linking with C
whitespace \n
funcname sleep
whitespace
argument n
whitespace
argument w
whitespace
punctuation =
whitespace
keyword code
punctuation {
whitespace \n
abc-instruction ccall
whitespace
abc-argument sleep
whitespace
literal literal-string "I:I:A"
whitespace \n
punctuation }
...@@ -34,40 +34,40 @@ typevar a ...@@ -34,40 +34,40 @@ typevar a
whitespace \n whitespace \n
funcname foldl funcname foldl
whitespace whitespace
macroargument op argument op
whitespace whitespace
macroargument r argument r
whitespace whitespace
macroargument l argument l
whitespace whitespace
punctuation :== punctuation :==
whitespace whitespace
funcname funcname-onlyused foldl funcname funcname-onlyused foldl
whitespace whitespace
macroargumentinrhs r argumentinrhs r
whitespace whitespace
macroargumentinrhs l argumentinrhs l
whitespace \n whitespace \n
keyword where keyword where
whitespace \n whitespace \n
funcname foldl funcname foldl
whitespace whitespace
macroargument r argument r
whitespace whitespace
punctuation [] punctuation []
whitespace whitespace
punctuation = punctuation =
whitespace whitespace
macroargumentinrhs r argumentinrhs r
whitespace \n whitespace \n
funcname foldl funcname foldl
whitespace whitespace
macroargument r argument r
whitespace whitespace
punctuation [ punctuation [
macroargument a argument a
punctuation : punctuation :
macroargument x argument x
punctuation ] punctuation ]
whitespace whitespace
punctuation = punctuation =
...@@ -75,11 +75,11 @@ whitespace ...@@ -75,11 +75,11 @@ whitespace
funcname funcname-onlyused foldl funcname funcname-onlyused foldl
whitespace whitespace
punctuation ( punctuation (
macroargumentinrhs op argumentinrhs op
whitespace whitespace
macroargumentinrhs r argumentinrhs r
whitespace whitespace
macroargumentinrhs a argumentinrhs a
punctuation ) punctuation )
whitespace whitespace
macroargumentinrhs x argumentinrhs x
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