diff --git a/package-lock.json b/package-lock.json index f41b663..ba41f7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,231 +1,36 @@ { "name": "plantuml", - "version": "2.15.1", - "lockfileVersion": 2, + "version": "2.16.0", + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "plantuml", - "version": "2.15.1", - "license": "SEE LICENSE IN LICENSE.txt", - "dependencies": { - "linq-collections": "*", - "vscode-nls": "^2.0.2" - }, - "devDependencies": { - "@types/mocha": "^2.2.32", - "@types/node": "^6.0.40", - "@types/vscode": "^1.57.0", - "js-yaml": "^3.13.1", - "markdown-it": "^8.3.2", - "plist": "^3.0.2", - "typescript": "^3.7.2" - }, - "engines": { - "vscode": "^1.57.0" - } - }, - "node_modules/@types/mocha": { - "version": "2.2.32", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.32.tgz", - "integrity": "sha1-3aDabq8hldL/gI9CoXJbGhnn7Wk=", - "dev": true - }, - "node_modules/@types/node": { - "version": "6.0.46", - "resolved": "https://registry.npmjs.org/@types/node/-/node-6.0.46.tgz", - "integrity": "sha1-jZ5IVygx8FsRzEx5N1TUNDchnWI=", - "dev": true - }, - "node_modules/@types/vscode": { - "version": "1.57.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.57.0.tgz", - "integrity": "sha512-FeznBFtIDCWRluojTsi9c3LLcCHOXP5etQfBK42+ixo1CoEAchkw39tuui9zomjZuKfUVL33KZUDIwHZ/xvOkQ==", - "dev": true - }, - "node_modules/argparse": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", - "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=", - "dev": true, - "dependencies": { - "sprintf-js": "~1.0.2" - } - }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/entities": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", - "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", - "dev": true - }, - "node_modules/esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true, - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, - "dependencies": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/linkify-it": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz", - "integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=", - "dev": true, - "dependencies": { - "uc.micro": "^1.0.1" - } - }, - "node_modules/linq-collections": { - "version": "1.0.254", - "resolved": "https://registry.npmjs.org/linq-collections/-/linq-collections-1.0.254.tgz", - "integrity": "sha512-SGg0LG+sNfAYm5c3QRPJhAi9I/MtY8e0TjfftsSlsqNKDJPTH22Bcsaq6vlTitgZEfXbY1yn9U9YgwoyGGH2PA==" - }, - "node_modules/markdown-it": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.3.2.tgz", - "integrity": "sha1-30uGUw0Xw7yb7sO2jXcLkuoXrpY=", - "dev": true, - "dependencies": { - "argparse": "^1.0.7", - "entities": "~1.1.1", - "linkify-it": "^2.0.0", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.3" - }, - "bin": { - "markdown-it": "bin/markdown-it.js" - } - }, - "node_modules/mdurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", - "dev": true - }, - "node_modules/plist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.2.tgz", - "integrity": "sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==", - "dev": true, - "dependencies": { - "base64-js": "^1.5.1", - "xmlbuilder": "^9.0.7", - "xmldom": "^0.5.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, - "node_modules/typescript": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.2.tgz", - "integrity": "sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, - "node_modules/uc.micro": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.3.tgz", - "integrity": "sha1-ftUNXg+an7ClczeSWfKndFjVAZI=", - "dev": true - }, - "node_modules/vscode-nls": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-2.0.2.tgz", - "integrity": "sha1-gIUiOAhEuK0VNJmvXDsDkhrqAto=" - }, - "node_modules/xmlbuilder": { - "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", - "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/xmldom": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz", - "integrity": "sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==", - "dev": true, - "engines": { - "node": ">=10.0.0" - } - } - }, "dependencies": { + "@babel/parser": { + "version": "7.14.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.14.7.tgz", + "integrity": "sha512-X67Z5y+VBJuHB/RjwECp8kSl5uYi0BvRbNeWqkaJCVh+LiTPl19WBUfG627psSgp9rSf6ojuXghQM3ha6qHHdA==" + }, "@types/mocha": { - "version": "2.2.32", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.32.tgz", - "integrity": "sha1-3aDabq8hldL/gI9CoXJbGhnn7Wk=", + "version": "2.2.48", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz", + "integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw==", "dev": true }, "@types/node": { - "version": "6.0.46", - "resolved": "https://registry.npmjs.org/@types/node/-/node-6.0.46.tgz", - "integrity": "sha1-jZ5IVygx8FsRzEx5N1TUNDchnWI=", + "version": "6.14.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.13.tgz", + "integrity": "sha512-J1F0XJ/9zxlZel5ZlbeSuHW2OpabrUAqpFuC2sm2I3by8sERQ8+KCjNKUcq8QHuzpGMWiJpo9ZxeHrqrP2KzQw==", "dev": true }, "@types/vscode": { - "version": "1.57.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.57.0.tgz", - "integrity": "sha512-FeznBFtIDCWRluojTsi9c3LLcCHOXP5etQfBK42+ixo1CoEAchkw39tuui9zomjZuKfUVL33KZUDIwHZ/xvOkQ==", + "version": "1.70.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.70.0.tgz", + "integrity": "sha512-3/9Fz0F2eBgwciazc94Ien+9u1elnjFg9YAhvAb3qDy/WeFWD9VrOPU7CIytryOVUdbxus8uzL4VZYONA0gDtA==", "dev": true }, "argparse": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", - "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=", + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "dev": true, "requires": { "sprintf-js": "~1.0.2" @@ -238,9 +43,9 @@ "dev": true }, "entities": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", - "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", "dev": true }, "esprima": { @@ -250,9 +55,9 @@ "dev": true }, "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -260,9 +65,9 @@ } }, "linkify-it": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz", - "integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", + "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", "dev": true, "requires": { "uc.micro": "^1.0.1" @@ -274,51 +79,58 @@ "integrity": "sha512-SGg0LG+sNfAYm5c3QRPJhAi9I/MtY8e0TjfftsSlsqNKDJPTH22Bcsaq6vlTitgZEfXbY1yn9U9YgwoyGGH2PA==" }, "markdown-it": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.3.2.tgz", - "integrity": "sha1-30uGUw0Xw7yb7sO2jXcLkuoXrpY=", + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", "dev": true, "requires": { "argparse": "^1.0.7", "entities": "~1.1.1", "linkify-it": "^2.0.0", "mdurl": "^1.0.1", - "uc.micro": "^1.0.3" + "uc.micro": "^1.0.5" } }, "mdurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", + "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==", "dev": true }, "plist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.2.tgz", - "integrity": "sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.6.tgz", + "integrity": "sha512-WiIVYyrp8TD4w8yCvyeIr+lkmrGRd5u0VbRnU+tP/aRLxP/YadJUYOMZJ/6hIa3oUyVCsycXvtNRgd5XBJIbiA==", "dev": true, "requires": { "base64-js": "^1.5.1", - "xmlbuilder": "^9.0.7", - "xmldom": "^0.5.0" + "xmlbuilder": "^15.1.1" } }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, + "ts-expression-evaluator": { + "version": "1.3.14", + "resolved": "https://registry.npmjs.org/ts-expression-evaluator/-/ts-expression-evaluator-1.3.14.tgz", + "integrity": "sha512-V4AfZi7J91u0cIdiGH3ha6j4DwII4KHLdTS49TciQR+d2n0m53We7akAcHyUyxEIHXK7TEvG8Ue2uWTLjtTYKg==", + "requires": { + "@babel/parser": "^7.0.0" + } + }, "typescript": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.2.tgz", - "integrity": "sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==", + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", "dev": true }, "uc.micro": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.3.tgz", - "integrity": "sha1-ftUNXg+an7ClczeSWfKndFjVAZI=", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", "dev": true }, "vscode-nls": { @@ -327,15 +139,9 @@ "integrity": "sha1-gIUiOAhEuK0VNJmvXDsDkhrqAto=" }, "xmlbuilder": { - "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", - "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=", - "dev": true - }, - "xmldom": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz", - "integrity": "sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==", + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", + "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==", "dev": true } } diff --git a/package.json b/package.json index 3ebd1bf..e4b4747 100755 --- a/package.json +++ b/package.json @@ -365,16 +365,17 @@ "buildsyntax": "node ./scripts/build-syntax.js" }, "devDependencies": { - "@types/mocha": "^2.2.32", - "@types/node": "^6.0.40", - "@types/vscode": "^1.57.0", - "js-yaml": "^3.13.1", - "markdown-it": "^8.3.2", - "plist": "^3.0.2", - "typescript": "^3.7.2" + "@types/mocha": "^2.2.48", + "@types/node": "^6.14.13", + "@types/vscode": "^1.70.0", + "js-yaml": "^3.14.1", + "markdown-it": "^8.4.2", + "plist": "^3.0.6", + "typescript": "^3.9.10" }, "dependencies": { "linq-collections": "*", + "ts-expression-evaluator": "^1.3.14", "vscode-nls": "^2.0.2" } } diff --git a/src/plantuml/diagram/builtinfunctions.ts b/src/plantuml/diagram/builtinfunctions.ts new file mode 100644 index 0000000..815b69c --- /dev/null +++ b/src/plantuml/diagram/builtinfunctions.ts @@ -0,0 +1,306 @@ +// PlantUML Builtin functions +// https://plantuml.com/de/preprocessing#291cabbe982ff775 + +import * as vscode from 'vscode'; +import evaluate, { registerFunction } from 'ts-expression-evaluator' + +export class BuiltinFunctionsPreprocessor { + private _builtinFunctionRegularExpression = /%([a-z_]+)\(([^\)]+)?\)/ig; + private _quotesRegularExpression = /"/ig; + + private _filename: string = undefined; + private _pathname: string = undefined; + private _buildinfunction: string = undefined; + private _functionname: string = undefined; + private _functionarguments: string = undefined; + + constructor(fullQualifiedFilename: string) { + let i = fullQualifiedFilename.lastIndexOf("\\"); + this._filename = fullQualifiedFilename.substr(i + 1); + this._pathname = fullQualifiedFilename.substr(0, i + 1); + } + + public ProcessBuiltinFunctions(titleRaw: string): string { + let workstring = titleRaw; + + workstring = workstring.replace(this._builtinFunctionRegularExpression, (...args) => { + let result = args[0]; + this._buildinfunction = args[0]; + this._functionname = args[1]; + this._functionarguments = this.stripQuotes(args[2]); + console.log(`pathname: ${this._pathname}`); + console.log(`filename: ${this._filename}`); + console.log(`titlestring: ${titleRaw}`); + console.log(`buildinfunction: ${this._buildinfunction}`); + console.log(`functionname: ${this._functionname}`); + console.log(`functionarguments: ${this._functionarguments}`); + switch (this._functionname) { + // Process %darken("red", 20) + case "darken": + result = this.processDarken(); + break; + // Process %date("yyyy.MM.dd' at 'HH:mm") + case "date": + result = this.processDate(); + break; + // Process %dirpath() + case "dirpath": + result = this.processDirpath(); + break; + // Process %feature("theme") + case "feature": + result = this.processFeature(); + break; + // Process %false() + case "false": + result = this.processFalse(); + break; + // Process %file_exists("c:/foo/dummy.txt") + case "file_exists": + result = this.processFileExists(); + break; + // Process %filename() + case "filename": + result = this.processFilename(); + break; + // Process %function_exists("$some_function") + case "function_exists": + result = this.processFunctionExists(); + break; + // Process %get_variable_value("$my_variable") + case "get_variable_value": + result = this.processGetVariableValue(); + break; + // Process %getenv("OS") + case "getenv": + result = this.processGetenv(); + break; + // Process %intval("42") + case "intval": + result = this.processIntval(); + break; + // Process %is_dark("#000000") + case "is_dark": + result = this.processIsDark(); + break; + // Process %is_light("#000000") + case "is_light": + result = this.processIsLight(); + break; + // Process %lighten("red", 20) + case "lighten": + result = this.processLighten(); + break; + // Process %lower("Hello") + case "lower": + result = this.processLower(); + break; + // Process %newline() + case "newline": + result = this.processNewline(); + break; + // Process %not(2+2==4) + case "not": + result = this.processNot(); + break; + // Process %reverse_color("#FF7700") + case "reverse_color": + result = this.processReverseColor(); + break; + // Process %reverse_hsluv_color("#FF7700") + case "reverse_hsluv_color": + result = this.processReverseHsluvColor(); + break; + // Process %set_variable_value("$my_variable", "some_value") + case "set_variable_value": + result = this.processSetVariableValue(); + break; + // Process %string(1 + 2) + case "string": + result = this.processString(); + break; + // Process %strlen("foo") + case "strlen": + result = this.processStrlen(); + break; + // Process %strpos("abcdef", "ef") + case "strpos": + result = this.processStrpos(); + break; + // Process %substr("abcdef", 3, 2) + case "substr": + result = this.processSubstr(); + break; + // Process %true() + case "true": + result = this.processTrue(); + break; + // Process %upper("Hello") + case "upper": + result = this.processUpper(); + break; + // Process %variable_exists("$my_variable") + case "variable_exists": + result = this.processVariableExists(); + break; + // Process %version() + case "version": + result = this.processVersion(); + break; + // ... + default: + break; + } + return result; + }); + + return workstring; + } + + private splitString(stringToSplit: string): string[] { + let parts = stringToSplit.split(","); + return parts; + } + + private stripQuotes(stringwithquotes: string): string { + return stringwithquotes.replace(this._quotesRegularExpression, ""); + } + + private processDarken(): string { + return "darken"; + } + + private processDate(): string { + let tmplocale = vscode.env.language; + let today = new Date().toLocaleDateString(tmplocale); + return today; + } + + private processDirpath(): string { + return this._pathname; + } + + private processFeature(): string { + return "feature"; + } + + private processFalse(): string { + return "false"; + } + + private processFileExists(): string { + return "file_exists"; + } + + private processFilename(): string { + return this._filename; + } + + private processFunctionExists(): string { + return "function_exists"; + } + + private processGetVariableValue(): string { + return "get_variable_value"; + } + + private processGetenv(): string { + let result = "undefined"; + let env = process.env; + + if (env[this._functionarguments]) { + result = env[this._functionarguments]; + } + + return result; + } + + private processIntval(): string { + return this._functionarguments; + } + + private processIsDark(): string { + return "is_dark"; + } + + private processIsLight(): string { + return "is_light"; + } + + private processLighten(): string { + return "lighten"; + } + + private processLower(): string { + return this._functionarguments.toLowerCase(); + } + + private processNewline(): string { + return "newline"; + } + + private processNot(): string { + let result = "false"; + let check = evaluate(this._functionarguments); + if (check === true) { + result == "true"; + } + return result; + } + + private processReverseColor(): string { + return "reverse_color"; + } + + private processReverseHsluvColor(): string { + return "reverse_hsluv_color"; + } + + private processSetVariableValue(): string { + return "set_variable_value"; + } + + private processString(): string { + let result = evaluate(this._functionarguments); + return String(result); + } + + private processStrlen(): string { + return String(this._functionarguments.length); + } + + private processStrpos(): string { + let parts = this.splitString(this._functionarguments); + return String(parts[0].indexOf(parts[1])); + } + + private processSubstr(): string { + let result = undefined; + let parts = this._functionarguments.split(","); + switch (parts.length) { + case 3: + result = parts[0].substr(Number(parts[1]), Number(parts[2])); + break; + default: + result = parts[0].substr(Number(parts[1])); + break; + } + return result; + } + + private processTrue(): string { + return "true"; + } + + private processUpper(): string { + return this._functionarguments.toUpperCase(); + } + + private processVariableExists(): string { + return "variable_exists"; + } + + private processVersion(): string { + return "version"; + } +} diff --git a/src/plantuml/diagram/diagram.ts b/src/plantuml/diagram/diagram.ts index e9a4f77..1e5e7dc 100644 --- a/src/plantuml/diagram/diagram.ts +++ b/src/plantuml/diagram/diagram.ts @@ -3,6 +3,7 @@ import * as path from 'path'; import * as title from './title'; import { DiagramType, getType } from './type'; +import { BuiltinFunctionsPreprocessor } from './builtinfunctions'; import { getContentWithInclude } from './include'; export const diagramStartReg = /@start(\w+)/i; @@ -24,6 +25,7 @@ export class Diagram { private _index: number = undefined; private _pageCount: number = undefined; private _contentWithInclude: string = undefined; + private _builtinFunctions: BuiltinFunctionsPreprocessor = undefined; constructor(content: string); constructor(content: string, document: vscode.TextDocument, start: vscode.Position, end: vscode.Position); @@ -41,6 +43,7 @@ export class Diagram { if (i >= 0) this.fileName = this.fileName.substr(0, i); this.dir = path.dirname(this.path); if (!path.isAbsolute(this.dir)) this.dir = ""; + this._builtinFunctions = new BuiltinFunctionsPreprocessor(this.path); } public get index(): number { if (this._index !== undefined) { @@ -97,22 +100,24 @@ export class Diagram { let matches: RegExpMatchArray;; if (matches = this.lines[0].match(RegFName)) { this._nameRaw = matches[2]; - this._name = title.Deal(this._nameRaw); + let tempName = this._builtinFunctions.ProcessBuiltinFunctions(this._nameRaw); + this._name = title.Deal(tempName); return; } - // // don't use title as diagram name, #438, #400, #409 - // let inlineTitle = /^\s*title\s+(.+?)\s*$/i; - // let multLineTitle = /^\s*title\s*$/i; - // for (let text of this.lines) { - // if (inlineTitle.test(text)) { - // let matches = text.match(inlineTitle); - // this._titleRaw = matches[1]; - // } - // } - // if (this._titleRaw) { - // this._title = title.Deal(this._titleRaw); - // return - // } + // don't use title as diagram name, #438, #400, #409 + let inlineName = /^\s*title\s+(.+?)\s*$/i; + let multLineName = /^\s*title\s*$/i; + for (let text of this.lines) { + if (inlineName.test(text)) { + let matches = text.match(inlineName); + this._nameRaw = matches[1]; + } + } + if (this._nameRaw) { + let tempName = this._builtinFunctions.ProcessBuiltinFunctions(this._nameRaw); + this._name = title.Deal(tempName); + return + } if (this.start && this.end) { // this.title = `${this.fileName}@${this.start.line + 1}-${this.end.line + 1}`; if (this.index)