Verified Commit 2801b0d4 authored by Camil Staps's avatar Camil Staps 🙂

Add typedef highlighting to highlightFunction

parent 676fce67
......@@ -110,6 +110,7 @@ function highlightFunction(func, callback, start) {
[/(instance)(\s)/, ['keyword', 'whitespace'], 'instance'],
[/(derive)(\s)/, ['keyword', 'whitespace'], 'derive'],
[/(class)(\s)/, ['keyword', 'whitespace'], 'className'],
[/(::)/, ['punctuation'], 'typeDefName'],
[/(\S+)(\s+)(::)/,
['funcname', 'whitespace', 'punctuation'], 'type'],
[/(\()(\S+)(\))(\s+)(infix[rl]?)(\s*)(\d*)(\s*)(::)/,
......@@ -175,13 +176,13 @@ function highlightFunction(func, callback, start) {
[/(\/\/.*)/, ['comment']],
[/(where)/, ['keyword'], 'pop'],
[/([a-z][\w`]*)/, ['typevar']],
[/(A)(\.)/, ['existential', 'punctuation'], 'univars'],
[/(A)(\.)/, ['existential', 'punctuation'], 'quantifiedVariables'],
[/([A-Z_]\w*)/, ['type']],
[/(\(\))/, ['type']],
[/(\|)/, ['punctuation'], 'context'],
[/(\W)/, ['punctuation']]
],
univars: [
quantifiedVariables: [
[/(\s+)/, ['whitespace']],
[/(\*)/, ['punctuation']],
[/(:)/, ['punctuation'], 'pop'],
......@@ -375,121 +376,104 @@ function highlightFunction(func, callback, start) {
[/(\s)/, ['whitespace']],
[/(\|.*\n)/, ['comment'], 'pop'],
[/(\S+)/, ['abc-directive'], 'pop;abcArgument']
]
}, func, myCallback, start);
}
function highlightTypeDef(type, callback, start) {
return highlightToHTML({
start: [
[/(::)/, ['punctuation'], 'name']
],
name: [
typeDefName: [
[/(\s+)/, ['whitespace']],
[/(\/\*)/, ['comment'], 'comment'],
[/(\*)/, ['punctuation']],
[/(\(?:==)/, ['punctuation'], 'synonym'],
[/(=:?)/, ['punctuation'], 'rhs'],
[/(\(?:==)/, ['punctuation'], 'pop;typeDefSynonym'],
[/(=:?)/, ['punctuation'], 'pop;typeDefRhs'],
[/([A-Z_][\w`]*)/, ['type']],
[/(\[! \])/, ['type']], // Special cases for head-strict and tail-strict lists;
[/(\[ !\])/, ['type']], // we don't want to parse whitespace there
[/([~@#\$%\^\?!\+\-\*<>\\\/\|&=:\[\]{}(,)]+)/, ['type']],
[/([a-z_`][\w`]*)/, ['typevar'], 'vars']
[/([a-z_`][\w`]*)/, ['typevar'], 'pop;typeDefVars']
],
vars: [
typeDefVars: [
[/(\s+)/, ['whitespace']],
[/(\/\*)/, ['comment'], 'comment'],
[/([a-z][\w`]*)/, ['typevar']],
[/(\(?:==)/, ['punctuation'], 'synonym'],
[/(=:?)/, ['punctuation'], 'rhs']
[/(\(?:==)/, ['punctuation'], 'pop;typeDefSynonym'],
[/(=:?)/, ['punctuation'], 'pop;typeDefRhs']
],
synonym: [
typeDefSynonym: [
[/(\s+)/, ['whitespace']],
[/([a-z][a-zA-Z]*)/, ['typevar']],
[/([A-Z_]\w*)/, ['type']],
[/(\W)/, ['punctuation']]
],
rhs: [
[/(\s*)(E)(\.)/, ['whitespace', 'existential', 'punctuation'], 'rhsexi'],
[/(\s*)(\{)/, ['whitespace', 'punctuation'], 'record'],
[/(\s*)/, ['whitespace'], 'conses']
typeDefRhs: [
[/(\s*)(E)(\.)/, ['whitespace', 'existential', 'punctuation'], 'pop;typeDefRhsExi'],
[/(\s*)(\{)/, ['whitespace', 'punctuation'], 'pop;typeDefRecord'],
[/(\s*)/, ['whitespace'], 'pop;typeDefADT']
],
rhsexi: [
typeDefRhsExi: [
[/(\s+)/, ['whitespace']],
[/([a-z][\w`]*)/, ['typevar']],
[/(:)/, ['punctuation'], 'rhs']
[/(:)/, ['punctuation'], 'pop;typeDefRhs']
],
record: [
typeDefRecord: [
[/(\s+)/, ['whitespace']],
[/([a-z_][\w`]*)(\s+)(::)/,
['field', 'whitespace', 'punctuation'],
'fieldtype'],
['field', 'whitespace', 'punctuation'], 'typeDefFieldType'],
[/(\})/, ['punctuation']]
],
fieldtype: [
typeDefFieldType: [
[/(\/\/.*)/, ['comment']],
[/(\s+)/, ['whitespace']],
[/([a-z]\w*)/, ['typevar']],
[/([A-Z_]\w*)/, ['type']],
[/(\()/, ['punctuation'], 'tuple'],
[/([\[\{])/, ['punctuation'], 'fieldtype'],
[/(\()/, ['punctuation'], 'typeDefTuple'],
[/([\[\{])/, ['punctuation'], 'typeDefFieldType'],
[/([\]\},])/, ['punctuation'], 'pop'],
[/(\W)/, ['punctuation']]
],
tuple: [
typeDefTuple: [
[/(\s+)/, ['whitespace']],
[/([a-z]\w*)/, ['typevar']],
[/([A-Z_]\w*)/, ['type']],
[/([\(\[\{])/, ['punctuation'], 'tuple'],
[/([\(\[\{])/, ['punctuation'], 'typeDefTuple'],
[/([\)\]\}])/, ['punctuation'], 'pop'],
[/(\W)/, ['punctuation']]
],
conses: [
typeDefADT: [
[/(\s+)/, ['whitespace']],
[/(E)(\.)/, ['existential', 'punctuation'], 'consexi'],
[/([A-Z_][\w`]*)/, ['constructor'], 'consargs'],
[/(\([~@#\$%\^\?!\+\-\*<>\\\/\|&=:]*\))/, ['constructor'], 'consargs'],
[/(E)(\.)/, ['existential', 'punctuation'], 'quantifiedVariables'],
[/([A-Z_][\w`]*)/, ['constructor'], 'typeDefConsArgs'],
[/(\([~@#\$%\^\?!\+\-\*<>\\\/\|&=:]*\))/, ['constructor'], 'typeDefConsArgs'],
[/(\.\.)/, ['punctuation']]
],
consexi: [
[/(\s+)/, ['whitespace']],
[/([a-z][\w`]*)/, ['typevar']],
[/(:)/, ['punctuation'], 'pop']
],
consargs: [
typeDefConsArgs: [
[/(\/\/.*)/, ['comment']],
[/(\n(?=\S))/, ['whitespace'], 'pop:2'],
[/(\s+)/, ['whitespace']],
[/(infix[lr]?)(\s*)(\d*)(\s+)/,
['keyword', 'whitespace', 'keyword', 'whitespace']],
[/([a-z][\w`]*)/, ['typevar']],
[/(A)(\.)/, ['existential', 'punctuation'], 'consexi'],
[/(A)(\.)/, ['existential', 'punctuation'], 'quantifiedVariables'],
[/([A-Z]\w*)/, ['type']],
[/(\|)/, ['punctuation'], 'pop'],
[/(&)/, ['punctuation'], 'context'],
[/(&)/, ['punctuation'], 'pop;typeDefContext'],
[/(\W)/, ['punctuation']]
],
context: [
typeDefContext: [
[/(\s+)/, ['whitespace']],
[/(,)/, ['punctuation']],
[/(\S+)(\{\|)/, ['generic', 'punctuation'], 'generic'],
[/(\S+)(\{\|)/, ['generic', 'punctuation'], 'typeDefContextGeneric'],
[/([^\s{]+)(,)/, ['classname', 'punctuation']],
[/([^\s{]+)/, ['classname'], 'contextType']
[/([^\s{]+)/, ['classname'], 'typeDefContextType']
],
generic: [
typeDefContextGeneric: [
[/([*>-]+\|\},)/, ['punctuation'], 'pop'],
[/([*>-]+\|\})/, ['punctuation'], 'pop;contextType']
[/([*>-]+\|\})/, ['punctuation'], 'pop;typeDefContextType']
],
contextType: [
typeDefContextType: [
[/(\s+)/, ['whitespace']],
[/(&)/, ['punctuation'], 'pop'],
[/(\|)/, ['punctuation'], 'pop:3'],
[/(\|)/, ['punctuation'], 'pop:2'],
[/([^\s,]+)/, ['typevar']]
],
comment: [
[/(\*\/)/, ['comment'], 'pop'],
[/([^*\/]+)/, ['comment']]
]
}, type, callback, start);
}, func, myCallback, start);
}
function highlightType(type, callback) {
......
......@@ -84,9 +84,6 @@ function runTestCase(testcase) {
case 'Function':
f = highlightFunction;
break;
case 'TypeDef':
f = highlightTypeDef;
break;
default:
process.stderr.write(RED + 'Unknown test type "' + testcase.type + '"' + RESET + '\n');
process.exit(1);
......
TypeDef
Function
-----
:: SDS p r w
= SDSSource (SDSSource p r w)
......
TypeDef
Function
-----
:: Server ci st =
{ idleTimeout :: Maybe Int //* Time between ticks when nothing happens in ms
......
TypeDef
Function
-----
:: WebService r w =
{ urlMatchPred :: !(String -> Bool) // checks whether the URL is served by this service
......
Function
-----
:: List = E.e: Cons e List | Nil
Start = Cons 5 (Cons 'a' (Cons "abc" Nil))
-----
punctuation ::
whitespace
type List
whitespace
punctuation =
whitespace
existential E
punctuation .
typevar e
punctuation :
whitespace
constructor Cons
whitespace
typevar e
whitespace
type List
whitespace
punctuation |
whitespace
constructor Nil
whitespace \n
funcname Start
whitespace
punctuation =
whitespace
constructor Cons
whitespace
literal literal-int literal-int-dec 5
whitespace
punctuation (
constructor Cons
whitespace
literal literal-char 'a'
whitespace
punctuation (
constructor Cons
whitespace
literal literal-string "abc"
whitespace
constructor Nil
punctuation ))
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