Fixed MEL Syntax Highlighter

Fixed grouping errors. Added mel.mel file to test.
This commit is contained in:
Nicholas Breslow 2013-10-02 14:17:35 -04:00
commit 55a947ec68
4 changed files with 76 additions and 38 deletions

View file

@ -78,6 +78,7 @@ var docs = {
"docs/textile.textile": {name: "Textile", wrapped: true},
"docs/c9search.c9search_results": "C9 Search Results",
"docs/mel.mel": "MEL",
"docs/Nix.nix": "Nix"
};

View file

@ -0,0 +1,49 @@
proc float edgeCalc(string $edge)
{
float $distance;
select -r `polyListComponentConversion -tv`;
string $connectedVerts[] = `filterExpand -ex 1 -sm 31`;
vector $PT1 = `pointPosition -w $connectedVerts[0]`;
vector $PT2 = `pointPosition -w $connectedVerts[1]`;
float $distance = mag(($PT1-$PT2));
return $distance;
}
global proc edgeLength()
{
source roundoff.mel;
string $edges[]= `filterExpand -ex 1 -sm 32`;
string $unit = `currentUnit -q -l`;
float $edgeLength[];
int $conversion = 10;
float $totalLength=0; // <= Init your sum variable
//save edgelength to var for later
for($i=0;$i<`size $edges`;$i++)
{
select -r $edges[$i]; // Select only one edge
$edgeLength[$i] = edgeCalc($edges[$i]);
$totalLength += $edgeLength[$i] * $conversion;
}
float $rounded_mm = `roundoff $totalLength 0`;
float $rounded_m = `roundoff (($totalLength)/1000) 2`;
string $edgeno = (size($edgeLength));
string $edgenoprint;
if(size($edgeLength)>1) {
$edgenoprint = " edges";
}
else {
$edgenoprint = " edge";
}
print ($rounded_mm + " mm / " +$rounded_m+ " m - Total length of " + $edgeno + $edgenoprint +"\n");
select -r $edges; // restore previous selection
}

View file

@ -3,7 +3,7 @@
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -26,17 +26,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Contributor(s):
*
*
*
* ***** END LICENSE BLOCK ***** */
/*
THIS FILE WAS AUTOGENERATED BY mode.tmpl.js
*/
define(function(require, exports, module) {
"use strict";
@ -44,20 +35,20 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var MELHighlightRules = require("./mel_highlight_rules").MELHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = new MELHighlightRules();
this.foldingRules = new FoldMode();
var highlighter = new MELHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
// Extra logic goes here.
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -77,9 +77,10 @@ var MELHighlightRules = function() {
regex: '"',
next: 'pop' },
{ defaultToken: 'string.quoted.double.mel' } ] },
{ todo: 'fix grouping',
token: [ 'variable.other.mel', 'punctuation.definition.variable.mel' ],
regex: '(\\$)[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*?\\b' },
{ token: [ 'variable.other.mel', 'punctuation.definition.variable.mel' ],
regex: '(\\$)([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*?\\b)' },
{ token: 'punctuation.definition.string.begin.mel',
regex: '\'',
push:
@ -88,8 +89,10 @@ var MELHighlightRules = function() {
regex: '\'',
next: 'pop' },
{ defaultToken: 'string.quoted.single.mel' } ] },
{ token: 'constant.language.mel',
regex: '\\b(false|true|yes|no|on|off)\\b' },
{ token: 'punctuation.definition.comment.mel',
regex: '/\\*',
push:
@ -97,35 +100,29 @@ var MELHighlightRules = function() {
regex: '\\*/',
next: 'pop' },
{ defaultToken: 'comment.block.mel' } ] },
{ todo: 'fix grouping',
token:
[ 'comment.line.double-slash.mel',
'punctuation.definition.comment.mel' ],
regex: '(//).*$\\n?' },
{ token: [ 'comment.line.double-slash.mel', 'punctuation.definition.comment.mel' ],
regex: '(//)(.*$\\n?)' },
{ caseInsensitive: true,
token: 'keyword.operator.mel',
regex: '\\b(instanceof)\\b' },
{ token: 'keyword.operator.symbolic.mel',
regex: '[-\\!\\%\\&\\*\\+\\=\\/\\?\\:]' },
{ todo: 'fix grouping',
token:
[ 'meta.preprocessor.mel',
'punctuation.definition.preprocessor.mel' ],
regex: '^[ \\t]*(#)[a-zA-Z]+' },
{ todo: 'fix grouping',
token:
[ 'meta.function.mel',
'keyword.other.mel',
'storage.type.mel',
'entity.name.function.mel',
'punctuation.section.function.mel' ],
regex: '((?:global\\s*)?proc)\\s*(\\w+\\s*\\[?\\]?\\s+|\\s+)([A-Za-z_][A-Za-z0-9_\\.]*)\\s*(\\()',
{ token: [ 'meta.preprocessor.mel', 'punctuation.definition.preprocessor.mel' ],
regex: '(^[ \\t]*)((?:#)[a-zA-Z]+)' },
{ token: [ 'meta.function.mel', 'keyword.other.mel', 'storage.type.mel', 'entity.name.function.mel', 'punctuation.section.function.mel' ],
regex: '((?:global\\s*)?proc)\\s*(\\w+\\s*\\[?\\]?\\s+|\\s+)([A-Za-z_][A-Za-z0-9_\\.]*)(\\s*(\\())',
push:
[ { include: '$self' },
{ token: 'punctuation.section.function.mel',
regex: '\\)',
next: 'pop' },
{ defaultToken: 'meta.function.mel' } ] } ] }
{ defaultToken: 'meta.function.mel' } ] }
] }
this.normalizeRules();
};