Verified Commit fa821597 authored by Camil Staps's avatar Camil Staps 🙂

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

parent d5f9ecb1
......@@ -8,12 +8,12 @@
font-weight: bold;
}
.funcname.funcname-onlyused, .macroargument {
.funcname.funcname-onlyused, .argument {
color: #6e94ad;
font-weight: normal;
}
.macroargumentinrhs {
.argumentinrhs {
color: #888;
}
......@@ -56,3 +56,16 @@
.literal {
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) {
if (cls == '__type__')
return highlightFunction(str, callback);
if (cls == 'macroargument')
if (cls == 'argument')
macroargs.push(str);
else if (macroargs.indexOf(str) >= 0)
return callback(
span.replace('class="' + cls + '"', 'class="macroargumentinrhs"'),
'macroargumentinrhs', str);
span.replace('class="' + cls + '"', 'class="argumentinrhs"'),
'argumentinrhs', str);
if (typeof callback == 'function')
return callback(span, cls, str);
......@@ -122,11 +122,25 @@ function highlightFunction(func, callback, start) {
[/(foreign export(?: (?:c|std)call)?)/,
['keyword']],
[/(\/\/.*)/, ['comment']],
[/(\/\*)/, ['comment'], 'comment'],
[/([\(\)])/, ['punctuation']],
[/(::)/, ['punctuation'], 'type'],
[/(=>)/, ['punctuation']],
[/(")/, ['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
[/(\s+)/, ['whitespace']],
......@@ -215,18 +229,11 @@ function highlightFunction(func, callback, start) {
['__type__']],
[/\b(where|with)\b/, ['keyword'], 'pop;macro'],
[/(special)(\s)/,['keyword', 'whitespace'], 'special'],
[/(\()(\S+)(\))/, ['punctuation', 'funcname', 'punctuation'], 'macroargs'],
[/(\S+)/, ['funcname'], 'macroargs']
[/(\()(\S+)(\))/, ['punctuation', 'funcname', 'punctuation'], 'funcargs'],
[/(\S+)/, ['funcname'], 'funcargs']
],
macroargs: [
[/(\s+)/, ['whitespace']],
[/((?::=)?=)/, ['punctuation'], 'pop;macrorhs'],
[/([:\[\](),]+)/, ['punctuation']],
[/(\|)/, ['punctuation'], 'pop;macroguard'],
[/([^:\[\](),\s]+)/, ['macroargument']]
],
macroguard: [
[/((?:^|\s)= )/, ['punctuation'], 'pop;macrorhs'],
guard: [
[/((?:^|\s)= )/, ['punctuation'], 'pop;rhs'],
[/(\s+)/, ['whitespace']],
[/(otherwise)/, ['keyword']],
[/('(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))')/,
......@@ -247,8 +254,8 @@ function highlightFunction(func, callback, start) {
[/([\w`]+)/, ['funcname funcname-onlyused']],
[/(.)/, ['punctuation']]
],
macrorhs: [
[/(\n)(\|)/, ['whitespace', 'punctuation'], 'pop;macroguard'],
rhs: [
[/(\n)(\|)/, ['whitespace', 'punctuation'], 'pop;guard'],
[/(\n)/, ['whitespace'], 'pop'],
[/(\s+)/, ['whitespace']],
[/(\/\/.*)/, ['comment']],
......@@ -299,6 +306,7 @@ function highlightFunction(func, callback, start) {
],
classHeading: [
[/(\/\/.*)/, ['comment']],
[/(\s+)(where)/, ['whitespace', 'keyword']],
[/(\n)/, ['whitespace'], 'pop'],
[/(\s)/, ['whitespace']],
[/(class)/, ['keyword'], 'className'],
......@@ -331,13 +339,40 @@ function highlightFunction(func, callback, start) {
[/(\S+)/, ['generic'], 'type'],
],
abc: [
[/(\s+)/, ['whitespace']],
[/(\|.*)/, ['comment']],
[/(\.)/, ['abc-directive'], 'abcDirective'],
[/(\s+)/, ['whitespace'], 'abcInstruction'],
[/(\|.*\n)/, ['comment']],
[/(})/, ['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/,
['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);
}
......
......@@ -94,17 +94,17 @@ punctuation (
funcname >>=
punctuation )
whitespace
macroargument ma
argument ma
whitespace
macroargument a2mb
argument a2mb
whitespace
punctuation :==
whitespace
funcname funcname-onlyused bind
whitespace
macroargumentinrhs ma
argumentinrhs ma
whitespace
macroargumentinrhs a2mb
argumentinrhs a2mb
whitespace \n
punctuation (
funcname `b`
......@@ -148,17 +148,17 @@ punctuation (
funcname `b`
punctuation )
whitespace
macroargument ma
argument ma
whitespace
macroargument a2mb
argument a2mb
whitespace
punctuation :==
whitespace
funcname funcname-onlyused bind
whitespace
macroargumentinrhs ma
argumentinrhs ma
whitespace
macroargumentinrhs a2mb
argumentinrhs a2mb
whitespace \n
punctuation (
funcname >>|
......@@ -198,13 +198,13 @@ punctuation (
funcname >>|
punctuation )
whitespace
macroargument ma
argument ma
whitespace
macroargument mb
argument mb
whitespace
punctuation :==
whitespace
macroargumentinrhs ma
argumentinrhs ma
whitespace
punctuation >>=
whitespace
......@@ -213,7 +213,7 @@ argument argument-wildcard _
whitespace
punctuation ->
whitespace
macroargumentinrhs mb
argumentinrhs mb
punctuation )
whitespace \n
punctuation (
......@@ -258,14 +258,14 @@ punctuation (
funcname =<<
punctuation )
whitespace
macroargument f
argument f
whitespace
macroargument x
argument x
whitespace
punctuation :==
whitespace
macroargumentinrhs x
argumentinrhs x
whitespace
punctuation >>=
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
whitespace \n
funcname foldl
whitespace
macroargument op
argument op
whitespace
macroargument r
argument r
whitespace
macroargument l
argument l
whitespace
punctuation :==
whitespace
funcname funcname-onlyused foldl
whitespace
macroargumentinrhs r
argumentinrhs r
whitespace
macroargumentinrhs l
argumentinrhs l
whitespace \n
keyword where
whitespace \n
funcname foldl
whitespace
macroargument r
argument r
whitespace
punctuation []
whitespace
punctuation =
whitespace
macroargumentinrhs r
argumentinrhs r
whitespace \n
funcname foldl
whitespace
macroargument r
argument r
whitespace
punctuation [
macroargument a
argument a
punctuation :
macroargument x
argument x
punctuation ]
whitespace
punctuation =
......@@ -75,11 +75,11 @@ whitespace
funcname funcname-onlyused foldl
whitespace
punctuation (
macroargumentinrhs op
argumentinrhs op
whitespace
macroargumentinrhs r
argumentinrhs r
whitespace
macroargumentinrhs a
argumentinrhs a
punctuation )
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