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

Add highlighting for imports

parent 9fd204ee
......@@ -7,12 +7,12 @@
outline: 1px solid red;
}
.funcname {
.funcname, .modulename {
color: #5998c2;
font-weight: bold;
}
.funcname.funcname-onlyused, .argument {
.funcname.funcname-onlyused, .modulename.modulename-onlyused, .argument {
color: #6e94ad;
font-weight: normal;
}
......
......@@ -117,6 +117,7 @@ function highlightClean(func, callback, start) {
return span;
};
var paren_depth = 0;
var indent = 0;
var i = 0;
......@@ -141,7 +142,7 @@ function highlightClean(func, callback, start) {
}
}],
[/([^\n\S]+)/, ['whitespace']],
[/(.+)/, ['error']]
[/(.)/, ['error']]
],
comment: [
[/([^*\\]+)/, ['comment']],
......@@ -152,7 +153,9 @@ function highlightClean(func, callback, start) {
start: [
[/(generic)(\s)/,
['keyword', 'whitespace'], 'generic'],
[/(where|from(?: library)?|import(?: code)?|qualified|as|(?:(?:definition|implementation|system) )?module)(\s)/,
[/(import)(\s)/, ['keyword', 'whitespace'], 'import'],
[/(from)(\s)/, ['keyword', 'whitespace'], 'importFrom'],
[/(where|(?:(?:definition|implementation|system) )?module)(\s)/,
['keyword', 'whitespace']],
[/(instance)(\s)/, ['keyword', 'whitespace'], 'instance'],
[/(derive)(\s)/, ['keyword', 'whitespace'], 'derive'],
......@@ -465,6 +468,68 @@ function highlightClean(func, callback, start) {
[/(&)/, ['punctuation'], 'pop'],
[/(\|)/, ['punctuation'], 'pop:2'],
[/([^\s,]+)/, ['typevar']]
],
import: [
[/(,)/, ['punctuation']],
[/(=>)(\s+)(qualified\b)/, ['punctuation', 'whitespace', 'keyword'], 'importSelections'],
[/(qualified\b)/, ['keyword']],
[/(as\b)/, ['keyword'], 'importAs'],
[/(code\s+from(?:\s+library)?\s+)(")/, ['keyword', 'literal literal-string'], 'string'],
[/([^,\s]+)/, ['modulename']]
],
importAs: [
[/(,)/, ['punctuation'], 'pop'],
[/([^,\s]+)/, ['modulename modulename-onlyused']]
],
importFrom: [
[/([^,\s]+)(\s+)(import)/, ['modulename', 'whitespace', 'keyword'], 'importSelections']
],
importSelections: [
[/(,)([\s\n]*)/, ['punctuation', 'whitespace']],
[/(class\b)/, ['keyword'], 'importSelectionsClass'],
[/(instance\b)/, ['keyword'], 'importSelectionsInstance'],
[/(::)/, ['punctuation'], 'importSelectionsTypeDef'],
[/([^\s,]+)/, ['funcname']]
],
importSelectionsClass: [
[/(,)([\s\n]*)/, ['punctuation', 'whitespace'], 'pop'],
[/(\()/, ['punctuation'], 'importSelectionsClassMembers'],
[/([^\s,(]+)/, ['classname']]
],
importSelectionsClassMembers: [
[/(\))/, ['punctuation'], 'pop'],
[/(,)/, ['punctuation']],
[/(\.\.)/, ['punctuation']],
[/([^\s,)]+)/, ['funcname']]
],
importSelectionsInstance: [
[/(\S+)/, ['classname'], 'jump:importSelectionsInstanceType']
],
importSelectionsInstanceType: [
[/(,)/, function (m) { return paren_depth == 0 ? [['punctuation'], 'pop'] : [['punctuation']]; }],
[/([\(\[])/, function (m) { paren_depth++; return [['punctuation'], 'importSelectionsInstanceType']; }],
[/([\)\]])/, function (m) { paren_depth--; return [['punctuation'], 'pop']; }],
[/([a-z][\w`]*)/, ['typevar']],
[/([A-Z_][\w`]*)/, ['type']],
[/([^\s\(\)\[\],]+)/, ['typevar']]
],
importSelectionsTypeDef: [
[/(,)([\s\n]*)/, ['punctuation', 'whitespace'], 'pop'],
[/([^\s({,]+)/, ['type']],
[/(\()/, ['punctuation'], 'importSelectionsADTConses'],
[/(\{)/, ['punctuation'], 'importSelectionsRecordFields'],
],
importSelectionsADTConses: [
[/(\))/, ['punctuation'], 'pop'],
[/(,)/, ['punctuation']],
[/(\.\.)/, ['punctuation']],
[/([^\s,)]+)/, ['constructor']]
],
importSelectionsRecordFields: [
[/(\})/, ['punctuation'], 'pop'],
[/(,)/, ['punctuation']],
[/(\.\.)/, ['punctuation']],
[/([^\s},]+)/, ['field']]
]
}, func, myCallback, start);
}
......
This diff is collapsed.
-----
import Control.Monad => qualified join
from Text import <+, class Text(join,split), instance Text String
import code from "cTCP_121."
import code from library "kernel32_library"
-----
keyword import
whitespace
modulename Control.Monad
whitespace
punctuation =>
whitespace
keyword qualified
whitespace
funcname join
whitespace \n
keyword from
whitespace
modulename Text
whitespace
keyword import
whitespace
funcname <+
punctuation ,
whitespace
keyword class
whitespace
classname Text
punctuation (
funcname join
punctuation ,
funcname split
punctuation ),
whitespace
keyword instance
whitespace
classname Text
whitespace
type String
whitespace \n
keyword import
whitespace
keyword code from
literal literal-string "cTCP_121."
whitespace \n
keyword import
whitespace
keyword code from library
literal literal-string "kernel32_library"
-----
definition module Data.Foldable
/* TODO: imports */
import StdEnv, StdInt
from Control.Applicative import class Applicative (..), :: Const, class Alternative (..), class *>
from Control.Monad import class Monad (..), >>=, class MonadPlus (..)
from Data.Functor import class Functor (..)
from Data.Monoid import class Monoid (..), class Semigroup (..)
from Data.Maybe import :: Maybe
from StdOverloaded import class +, class one, class *, class zero, class <, class ==
from StdClass import class Ord
from StdFunc import flip
/**
* Ported from Haskell's Data.Foldable by Jurriën Stutterheim 15-08-2014
......@@ -246,7 +254,153 @@ keyword definition module
whitespace
funcname Data.Foldable
whitespace \n\n
comment /* TODO: imports */
keyword import
whitespace
modulename StdEnv
punctuation ,
whitespace
modulename StdInt
whitespace \n
keyword from
whitespace
modulename Control.Applicative
whitespace
keyword import
whitespace
keyword class
whitespace
classname Applicative
whitespace
punctuation (..),
whitespace
punctuation ::
whitespace
type Const
punctuation ,
whitespace
keyword class
whitespace
classname Alternative
whitespace
punctuation (..),
whitespace
keyword class
whitespace
classname *>
whitespace \n
keyword from
whitespace
modulename Control.Monad
whitespace
keyword import
whitespace
keyword class
whitespace
classname Monad
whitespace
punctuation (..),
whitespace
funcname >>=
punctuation ,
whitespace
keyword class
whitespace
classname MonadPlus
whitespace
punctuation (..)
whitespace \n
keyword from
whitespace
modulename Data.Functor
whitespace
keyword import
whitespace
keyword class
whitespace
classname Functor
whitespace
punctuation (..)
whitespace \n
keyword from
whitespace
modulename Data.Monoid
whitespace
keyword import
whitespace
keyword class
whitespace
classname Monoid
whitespace
punctuation (..),
whitespace
keyword class
whitespace
classname Semigroup
whitespace
punctuation (..)
whitespace \n
keyword from
whitespace
modulename Data.Maybe
whitespace
keyword import
whitespace
punctuation ::
whitespace
type Maybe
whitespace \n
keyword from
whitespace
modulename StdOverloaded
whitespace
keyword import
whitespace
keyword class
whitespace
classname +
punctuation ,
whitespace
keyword class
whitespace
classname one
punctuation ,
whitespace
keyword class
whitespace
classname *
punctuation ,
whitespace
keyword class
whitespace
classname zero
punctuation ,
whitespace
keyword class
whitespace
classname <
punctuation ,
whitespace
keyword class
whitespace
classname ==
whitespace \n
keyword from
whitespace
modulename StdClass
whitespace
keyword import
whitespace
keyword class
whitespace
classname Ord
whitespace \n
keyword from
whitespace
modulename StdFunc
whitespace
keyword import
whitespace
funcname flip
whitespace \n\n
comment /**\n * Ported from Haskell's Data.Foldable by Jurriën Stutterheim 15-08-2014\n */
whitespace \n\n
......
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