From b3e1091d15573d71d2481396b28ba82a0abfce8f Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 27 Sep 2018 14:44:14 +0200 Subject: [PATCH] v0.1.14: Add support for types in dynamic pattern matches --- clean.js | 3 ++ package.json | 2 +- tests/dynamic-pattern-match | 72 +++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/dynamic-pattern-match diff --git a/clean.js b/clean.js index b402e9c..bc302b0 100644 --- a/clean.js +++ b/clean.js @@ -209,6 +209,7 @@ var highlightRules = { [/([^\s;]+)/, ['modulename'], 'pop'] ], funcargs: [ + [/(::)/, ['punctuation'], 'type'], [/(=:)/, ['punctuation']], [/((?::=)?=)/, ['punctuation'], 'jump:rhs'], [/(\[\|)/, ['punctuation']], /* overloaded list */ @@ -253,6 +254,8 @@ var highlightRules = { [/(\(\))/, ['type']], [/(\()(->)(\))/, ['punctuation', 'type', 'punctuation']], [/(\|)/, ['punctuation'], 'context'], + [/(\()/, ['punctuation'], 'type'], + [/(\))/, ['punctuation'], 'pop'], [/([^\s\w])/, ['punctuation']] ], typeOfPattern: [ diff --git a/package.json b/package.json index c07977e..e4d571c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clean-highlighter", - "version": "0.1.13", + "version": "0.1.14", "description": "Clean language highlighter", "keywords": ["clean","highlighter"], "main": "clean.js", diff --git a/tests/dynamic-pattern-match b/tests/dynamic-pattern-match new file mode 100644 index 0000000..7f21952 --- /dev/null +++ b/tests/dynamic-pattern-match @@ -0,0 +1,72 @@ +----- +unpack :: Dynamic -> Maybe a +unpack (x :: a^) = Just x +unpack (f :: A.a: Int -> Maybe a) = Just (f 37) +unpack _ = Nothing +----- +funcname unpack +whitespace +punctuation :: +whitespace +type Dynamic +whitespace +punctuation -> +whitespace +type Maybe +whitespace +typevar a +whitespace \n +funcname unpack +whitespace +punctuation ( +argument x +whitespace +punctuation :: +whitespace +typevar a +punctuation ^) +whitespace +punctuation = +whitespace +constructor Just +whitespace +argumentinrhs x +whitespace \n +funcname unpack +whitespace +punctuation ( +argument f +whitespace +punctuation :: +whitespace +existential A +punctuation . +typevar a +punctuation : +whitespace +type Int +whitespace +punctuation -> +whitespace +type Maybe +whitespace +typevar a +punctuation ) +whitespace +punctuation = +whitespace +constructor Just +whitespace +punctuation ( +argumentinrhs f +whitespace +literal literal-int literal-int-dec 37 +punctuation ) +whitespace \n +funcname unpack +whitespace +argument _ +whitespace +punctuation = +whitespace +constructor Nothing -- GitLab