From e4355adae7f8fc6c7279bd7a22ed5caec1fd1848 Mon Sep 17 00:00:00 2001 From: baboso Date: Sat, 31 May 2014 19:51:41 -0400 Subject: [PATCH 1/8] Initial commit for praat highlighting: based on Perl --- lib/ace/mode/praat.js | 90 ++++++++++++++ lib/ace/mode/praat_highlight_rules.js | 165 ++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 lib/ace/mode/praat.js create mode 100644 lib/ace/mode/praat_highlight_rules.js diff --git a/lib/ace/mode/praat.js b/lib/ace/mode/praat.js new file mode 100644 index 00000000..69c4d27e --- /dev/null +++ b/lib/ace/mode/praat.js @@ -0,0 +1,90 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var PerlHighlightRules = require("./perl_highlight_rules").PerlHighlightRules; +var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; +var Range = require("../range").Range; +var CStyleFoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + this.HighlightRules = PerlHighlightRules; + + this.$outdent = new MatchingBraceOutdent(); + this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"}); +}; +oop.inherits(Mode, TextMode); + +(function() { + + this.lineCommentStart = "#"; + this.blockComment = [ + {start: "=begin", end: "=cut"}, + {start: "=item", end: "=cut"} + ]; + + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.getTokenizer().getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[\:]\s*$/); + if (match) { + indent += tab; + } + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; + + this.$id = "ace/mode/perl"; +}).call(Mode.prototype); + +exports.Mode = Mode; +}); diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js new file mode 100644 index 00000000..7c183fe3 --- /dev/null +++ b/lib/ace/mode/praat_highlight_rules.js @@ -0,0 +1,165 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var PerlHighlightRules = function() { + + var keywords = ( + "base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" + + "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars" + ); + + var buildinConstants = ("ARGV|ENV|INC|SIG"); + + var builtinFunctions = ( + "getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" + + "gethostbyname|getservbyport|getnetbyaddr|getnetbyname|getsockname|" + + "getpeername|setpriority|getprotoent|setprotoent|getpriority|" + + "endprotoent|getservent|setservent|endservent|sethostent|socketpair|" + + "getsockopt|gethostent|endhostent|setsockopt|setnetent|quotemeta|" + + "localtime|prototype|getnetent|endnetent|rewinddir|wantarray|getpwuid|" + + "closedir|getlogin|readlink|endgrent|getgrgid|getgrnam|shmwrite|" + + "shutdown|readline|endpwent|setgrent|readpipe|formline|truncate|" + + "dbmclose|syswrite|setpwent|getpwnam|getgrent|getpwent|ucfirst|sysread|" + + "setpgrp|shmread|sysseek|sysopen|telldir|defined|opendir|connect|" + + "lcfirst|getppid|binmode|syscall|sprintf|getpgrp|readdir|seekdir|" + + "waitpid|reverse|unshift|symlink|dbmopen|semget|msgrcv|rename|listen|" + + "chroot|msgsnd|shmctl|accept|unpack|exists|fileno|shmget|system|" + + "unlink|printf|gmtime|msgctl|semctl|values|rindex|substr|splice|" + + "length|msgget|select|socket|return|caller|delete|alarm|ioctl|index|" + + "undef|lstat|times|srand|chown|fcntl|close|write|umask|rmdir|study|" + + "sleep|chomp|untie|print|utime|mkdir|atan2|split|crypt|flock|chmod|" + + "BEGIN|bless|chdir|semop|shift|reset|link|stat|chop|grep|fork|dump|" + + "join|open|tell|pipe|exit|glob|warn|each|bind|sort|pack|eval|push|" + + "keys|getc|kill|seek|sqrt|send|wait|rand|tied|read|time|exec|recv|" + + "eof|chr|int|ord|exp|pos|pop|sin|log|abs|oct|hex|tie|cos|vec|END|ref|" + + "map|die|uc|lc|do" + ); + + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "constant.language": buildinConstants, + "support.function": builtinFunctions + }, "identifier"); + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = { + "start" : [ + { + token : "comment.doc", + regex : "^=(?:begin|item)\\b", + next : "block_comment" + }, { + token : "string.regexp", + regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" + }, { + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // multi line string start + regex : '["].*\\\\$', + next : "qqstring" + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : "string", // multi line string start + regex : "['].*\\\\$", + next : "qstring" + }, { + token : "constant.numeric", // hex + regex : "0x[0-9a-fA-F]+\\b" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : keywordMapper, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "%#|\\$#|\\.\\.\\.|\\|\\|=|>>=|<<=|<=>|&&=|=>|!~|\\^=|&=|\\|=|\\.=|x=|%=|\\/=|\\*=|\\-=|\\+=|=~|\\*\\*|\\-\\-|\\.\\.|\\|\\||&&|\\+\\+|\\->|!=|==|>=|<=|>>|<<|,|=|\\?\\:|\\^|\\||x|%|\\/|\\*|<|&|\\\\|~|!|>|\\.|\\-|\\+|\\-C|\\-b|\\-S|\\-u|\\-t|\\-p|\\-l|\\-d|\\-f|\\-g|\\-s|\\-z|\\-k|\\-e|\\-O|\\-T|\\-B|\\-M|\\-A|\\-X|\\-W|\\-c|\\-R|\\-o|\\-x|\\-w|\\-r|\\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)" + }, { + token : "comment", + regex : "#.*$" + }, { + token : "lparen", + regex : "[[({]" + }, { + token : "rparen", + regex : "[\\])}]" + }, { + token : "text", + regex : "\\s+" + } + ], + "qqstring" : [ + { + token : "string", + regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"', + next : "start" + }, { + token : "string", + regex : '.+' + } + ], + "qstring" : [ + { + token : "string", + regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'", + next : "start" + }, { + token : "string", + regex : '.+' + } + ], + "block_comment": [ + { + token: "comment.doc", + regex: "^=cut\\b", + next: "start" + }, + { + defaultToken: "comment.doc" + } + ] + }; +}; + +oop.inherits(PerlHighlightRules, TextHighlightRules); + +exports.PerlHighlightRules = PerlHighlightRules; +}); From df92a99e93c57439c6870466c111ef985085e4a4 Mon Sep 17 00:00:00 2001 From: baboso Date: Sun, 1 Jun 2014 18:25:27 -0400 Subject: [PATCH 2/8] Praat syntax highlighter, first release --- demo/kitchen-sink/docs/praat.praat | 115 ++++++++++ lib/ace/ext/modelist.js | 1 + lib/ace/mode/praat.js | 11 +- lib/ace/mode/praat_highlight_rules.js | 288 +++++++++++++++----------- 4 files changed, 290 insertions(+), 125 deletions(-) create mode 100644 demo/kitchen-sink/docs/praat.praat diff --git a/demo/kitchen-sink/docs/praat.praat b/demo/kitchen-sink/docs/praat.praat new file mode 100644 index 00000000..48a649a2 --- /dev/null +++ b/demo/kitchen-sink/docs/praat.praat @@ -0,0 +1,115 @@ +form Highlighter test + sentence My_sentence This should all be a string + text My_text This should also all be a string + word My_word Only the first word is a string, the rest is invalid + boolean Binary 1 + boolean Text no + boolean Quoted "yes" + comment This should be a string + real left_Range -123.6 + positive right_Range_max 3.3 + integer Int 4 + natural Nat 4 +endform + +# old-style procedure call +call oldStyle "quoted" 2 unquoted string +assert oldStyle.local = 1 + +# New-style procedure call with parens +@newStyle("quoted", 2, "quoted string") +if praatVersion >= 5364 + # New-style procedure call with colon + @newStyle: "quoted", 2, "quoted string" +endif +assert newStyle.local = 1 + +# if-block with built-in variables +if windows + # We are on Windows +elsif unix = 1 or !macintosh + # We are on Linux +else macintosh == 1 + # We are on Mac +endif + +# inline if with inline comment +var = if macintosh = 1 then 0 else 1 fi ; This is an inline comment + +# for-loop with explicit from using local variable +# and paren-style function calls and variable interpolation +n = numberOfSelected("Sound") +for i from newStyle.local to n + sound'i' = selected("Sound", i) + sound[i] = sound'i' +endfor + +for i from 1 to n + # Different styles of object selection + select sound'i' + sound = selected() + sound$ = selected$("Sound") + select Sound 'sound$' + selectObject(sound[i]) + selectObject: sound + + # New-style standalone command call + Rename: "SomeName" + + # Command call with assignment + duration = Get total duration + + # Multi-line command with modifier + pitch = noprogress To Pitch (ac): 0, 75, 15, "no", + ...0.03, 0.45, 0.01, 0.35, 0.14, 600 + + # Old-style command with assignment + minimum = Get minimum... 0 0 "Hertz" Parabolic + + # New-style multi-line command call with broken strings + table = Create Table with column names: "table", 0, + ..."file subject speaker + ...f0 f1 f2 f3 " + + ..."duration response" + + removeObject: pitch, table + + # Picture window commands + selectObject: sound + Select inner viewport: 1, 6, 0.5, 1.5 + Black + Draw... 0 0 0 0 "no" Curve + Draw inner box + Text bottom: "yes", sound$ + Erase all + + # Demo window commands + demo Erase all + demo Select inner viewport... 0 100 0 100 + demo Axes... 0 100 0 100 + demo Paint rectangle... white 0 100 0 100 + demo Purple + demo Times + demo 24 + # The "to" in "Click to finish" should not be a keyword + demo Text... 50 centre 50 half Click to finish + demoWaitForInput ( ) + demo Erase all + demo Select inner viewport... 0 100 0 100 + demo Axes... 0 100 0 100 + demo Paint rectangle... purple 0 100 0 100 + demo Yellow + demo Times + demo 24 + demo Text... 50 centre 50 half Finished +endfor + +# Old-style procedure declaration +procedure oldStyle .str1$ .num .str2$ + .local = 1 +endproc + +# New-style procedure declaration +procedure newStyle (.str1$, .num, .str2$) + .local = 1 +endproc diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index 66fe3de8..b4fbd0da 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -113,6 +113,7 @@ var supportedModes = { pgSQL: ["pgsql"], PHP: ["php|phtml"], Powershell: ["ps1"], + Praat: ["praat"], Prolog: ["plg|prolog"], Properties: ["properties"], Protobuf: ["proto"], diff --git a/lib/ace/mode/praat.js b/lib/ace/mode/praat.js index 69c4d27e..01d18c9a 100644 --- a/lib/ace/mode/praat.js +++ b/lib/ace/mode/praat.js @@ -33,13 +33,13 @@ define(function(require, exports, module) { var oop = require("../lib/oop"); var TextMode = require("./text").Mode; -var PerlHighlightRules = require("./perl_highlight_rules").PerlHighlightRules; +var PraatHighlightRules = require("./praat_highlight_rules").PraatHighlightRules; var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; var Range = require("../range").Range; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.HighlightRules = PerlHighlightRules; + this.HighlightRules = PraatHighlightRules; this.$outdent = new MatchingBraceOutdent(); this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"}); @@ -49,11 +49,6 @@ oop.inherits(Mode, TextMode); (function() { this.lineCommentStart = "#"; - this.blockComment = [ - {start: "=begin", end: "=cut"}, - {start: "=item", end: "=cut"} - ]; - this.getNextLineIndent = function(state, line, tab) { var indent = this.$getIndent(line); @@ -83,7 +78,7 @@ oop.inherits(Mode, TextMode); this.$outdent.autoOutdent(doc, row); }; - this.$id = "ace/mode/perl"; + this.$id = "ace/mode/praat"; }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 7c183fe3..693a6572 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -1,77 +1,106 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Distributed under the BSD license: - * - * Copyright (c) 2010, 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 - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * 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 - * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ***** END LICENSE BLOCK ***** */ - define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; -var PerlHighlightRules = function() { +var PraatHighlightRules = function() { var keywords = ( - "base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" + - "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars" + "if|then|else|elsif|elif|endif|fi|" + + "endfor|" + // other for-related keywords are specified below + "while|endwhile|" + + "repeat|until|" + + "select|plus|minus|" + + "assert" ); - var buildinConstants = ("ARGV|ENV|INC|SIG"); +// var buildinConstants = ("ARGV|ENV|INC|SIG"); - var builtinFunctions = ( - "getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" + - "gethostbyname|getservbyport|getnetbyaddr|getnetbyname|getsockname|" + - "getpeername|setpriority|getprotoent|setprotoent|getpriority|" + - "endprotoent|getservent|setservent|endservent|sethostent|socketpair|" + - "getsockopt|gethostent|endhostent|setsockopt|setnetent|quotemeta|" + - "localtime|prototype|getnetent|endnetent|rewinddir|wantarray|getpwuid|" + - "closedir|getlogin|readlink|endgrent|getgrgid|getgrnam|shmwrite|" + - "shutdown|readline|endpwent|setgrent|readpipe|formline|truncate|" + - "dbmclose|syswrite|setpwent|getpwnam|getgrent|getpwent|ucfirst|sysread|" + - "setpgrp|shmread|sysseek|sysopen|telldir|defined|opendir|connect|" + - "lcfirst|getppid|binmode|syscall|sprintf|getpgrp|readdir|seekdir|" + - "waitpid|reverse|unshift|symlink|dbmopen|semget|msgrcv|rename|listen|" + - "chroot|msgsnd|shmctl|accept|unpack|exists|fileno|shmget|system|" + - "unlink|printf|gmtime|msgctl|semctl|values|rindex|substr|splice|" + - "length|msgget|select|socket|return|caller|delete|alarm|ioctl|index|" + - "undef|lstat|times|srand|chown|fcntl|close|write|umask|rmdir|study|" + - "sleep|chomp|untie|print|utime|mkdir|atan2|split|crypt|flock|chmod|" + - "BEGIN|bless|chdir|semop|shift|reset|link|stat|chop|grep|fork|dump|" + - "join|open|tell|pipe|exit|glob|warn|each|bind|sort|pack|eval|push|" + - "keys|getc|kill|seek|sqrt|send|wait|rand|tied|read|time|exec|recv|" + - "eof|chr|int|ord|exp|pos|pop|sin|log|abs|oct|hex|tie|cos|vec|END|ref|" + - "map|die|uc|lc|do" + var predefinedVariables = ( + "macintosh|windows|unix|" + + "praatVersion|praatVersion\\$" + + "pi|undefined|" + + "newline\\$|tab\\$|" + + "shellDirectory\\$|homeDirectory\\$|preferencesDirectory\\$|" + + "temporaryDirectory\\$|defaultDirectory\\$" + ); + + var functions = ( +// Math functions + "writeInfo|writeInfoLine|appendInfo|appendInfoLine|" + + "writeFile|writeFileLine|appendFile|appendFileLine|" + + "abs|round|floor|ceiling|min|max|imin|imax|" + + "sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" + + "exp|ln|log10|log2|" + + "sinh|cosh|tanh|arcsinh|arccosh|actanh|" + + "sigmoid|invSigmoid|erf|erfc|" + + "randomUniform|randomInteger|randomGauss|randomPoisson|" + + "lnGamma|gaussP|gaussQ|invGaussQ|" + + "chiSquareP|chiSquareQ|invChiSquareQ|studentP|studentQ|invStudentQ|" + + "fisherP|fisherQ|invFisherQ|" + + "binomialP|binomialQ|invBinomialP|invBinomialQ|" + + "hertzToBark|barkToHerz|" + + "hertzToMel|melToHertz|" + + "hertzToSemitones|semitonesToHerz|" + + "erb|hertzToErb|erbToHertz|" + + "phonToDifferenceLimens|differenceLimensToPhon|" + + "beta|besselI|besselK|" + +// String functions + "selected|selected$|numberOfSelected|variableExists|"+ + "index|rindex|startsWith|endsWith|"+ + "index_regex|rindex_regex|replace_regex$|"+ + "length|extractWord$|extractLine$|extractNumber|" + + "left$|right$|mid$|replace$|" + +// Pause functions + "beginPause|endPause|" + +// Demo functions + "demoShow|demoWindowTitle|demoInput|demoWaitForInput|" + + "demoClicked|demoClickedIn|demoX|demoY|" + + "demoKeyPressed|demoKey$|" + + "demoExtraControlKeyPressed|demoShiftKeyPressed|"+ + "demoCommandKeyPressed|demoOptionKeyPressed|" + +// File functions + "environment$|" + + "chooseDirectory$|createDirectory|fileReadable|deleteFile|" + + "selectObject|removeObject|plusObject|minusObject|" + + "runScript|exitScript" ); + var objectTypes = ( + "Collection|Strings|ManPages|SortedSetOfString|Sound|Matrix|Polygon|" + + "PointProcess|ParamCurve|Spectrum|Ltas|Spectrogram|Formant|" + + "Excitation|Cochleagram|VocalTract|FormantPoint|FormantTier|" + + "FormantGrid|Label|Tier|Autosegment|Intensity|Pitch|Harmonicity|" + + "Transition|RealPoint|RealTier|PitchTier|IntensityTier|DurationTier|" + + "AmplitudeTier|SpectrumTier|Manipulation|TextPoint|TextInterval|" + + "TextTier|IntervalTier|TextGrid|LongSound|WordList|SpellingChecker|" + + "Movie|Corpus|TableOfReal|Distributions|PairDistribution|Table|" + + "LinearRegression|LogisticRegression|Art|Artword|Speaker|Activation|" + + "BarkFilter|Categories|Cepstrum|CCA|ChebyshevSeries|" + + "ClassificationTable|Confusion|Correlation|Covariance|Discriminant|" + + "DTW|Eigen|Excitations|FormantFilter|Index|KlattTable|Permutation|" + + "ISpline|LegendreSeries|MelFilter|MSpline|Pattern|PCA|Polynomial|" + + "Roots|SimpleString|StringsIndex|SpeechSynthesizer|SPINET|SSCP|SVD|" + + "AffineTransform|Procrustes|ContingencyTable|Dissimilarity|" + + "Similarity|Configuration|Distance|Salience|ScalarProduct|Weight|" + + "KlattGrid|HMM|HMM_State|HMM_Observation|HMM_ObservationSequence|" + + "HMM_StateSequence|GaussianMixture|Diagonalizer|MixingMatrix|" + + "CrossCorrelationTable|CrossCorrelationTables|Network|OTGrammar|" + + "OTHistory|OTMulti|FFNet|Cepstrumc|LPC|LFCC|MFCC|ExperimentMFC|" + + "ResultsMFC|EEG|ERPTier|ERP|KNN|FeatureWeights" + ); + var keywordMapper = this.createKeywordMapper({ "keyword": keywords, - "constant.language": buildinConstants, - "support.function": builtinFunctions +// "constant.language": buildinConstants, + "support.function": functions + }, "identifier"); + + var inlineIf = this.createKeywordMapper({ + "keyword": "(if|then|else|fi)", +// "constant.language": buildinConstants, + "support.function": functions }, "identifier"); // regexp must not have capturing parentheses. Use (?:) instead. @@ -80,86 +109,111 @@ var PerlHighlightRules = function() { this.$rules = { "start" : [ { - token : "comment.doc", - regex : "^=(?:begin|item)\\b", - next : "block_comment" + token : "entity.name.type", + regex : "(" + objectTypes + ")" }, { - token : "string.regexp", - regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" + token : "variable.language", + regex : "(" + predefinedVariables + ")" }, { - token : "string", // single line - regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + token : ["support.function", "text"], + regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())" }, { - token : "string", // multi line string start - regex : '["].*\\\\$', - next : "qqstring" +// token : ["keyword", "text", "keyword", "text", "keyword", "text"], +// regex : /\b(for)(\s+\S+\s*)(?:(from)(\s+[a-z][a-zA-Z0-9_.]*\$?\s*))?(?:(to)(\s+\S+\s*))?/, +// }, { + token : "keyword", + regex : /(\bfor\b)/, + next : "for" }, { - token : "string", // single line - regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + token : "keyword", + regex : "(\\b(?:" + keywords + ")\\b)" }, { - token : "string", // multi line string start - regex : "['].*\\\\$", - next : "qstring" + token : "string.interpolated", + regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/ }, { - token : "constant.numeric", // hex - regex : "0x[0-9a-fA-F]+\\b" + token : "string", + regex : /"[^"]*"/ }, { - token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + token : ["text", "keyword", "text", "entity.name.section"], // multi line string start + regex : /(^\s*)(\bform\b)(\s+)(.*)/, + next : "form" }, { - token : keywordMapper, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + token : "constant.numeric", + regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { + token : ["entity.name.function", "text"], + regex : /(@\S+)(:|\s*\()/ + }, { + token : ["text", "keyword", "text", "entity.name.function"], + regex : /(^\s*)(call)(\s+)(\S+)/ + }, { + token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"], + regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ + }, { + token : ["text", "keyword", "text", "keyword"], + regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ + }, { + token : ["text", "keyword"], + regex : /(^\s*)(demo\b)/ }, { token : "keyword.operator", - regex : "%#|\\$#|\\.\\.\\.|\\|\\|=|>>=|<<=|<=>|&&=|=>|!~|\\^=|&=|\\|=|\\.=|x=|%=|\\/=|\\*=|\\-=|\\+=|=~|\\*\\*|\\-\\-|\\.\\.|\\|\\||&&|\\+\\+|\\->|!=|==|>=|<=|>>|<<|,|=|\\?\\:|\\^|\\||x|%|\\/|\\*|<|&|\\\\|~|!|>|\\.|\\-|\\+|\\-C|\\-b|\\-S|\\-u|\\-t|\\-p|\\-l|\\-d|\\-f|\\-g|\\-s|\\-z|\\-k|\\-e|\\-O|\\-T|\\-B|\\-M|\\-A|\\-X|\\-W|\\-c|\\-R|\\-o|\\-x|\\-w|\\-r|\\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)" + regex : /(?:\b((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)\b)/ }, { token : "comment", regex : "#.*$" }, { - token : "lparen", - regex : "[[({]" + token : "text", + regex : /\s+/ + } + ], + "form" : [ + { + token : ["keyword", "text", "constant.numeric"], + regex : /((?:optionmenu|choice)\s+)(\S+:\s+)([0-9]+)/ }, { - token : "rparen", - regex : "[\\])}]" + token : ["keyword", "constant.numeric"], + regex : /((?:option|button)\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/ + }, { + token : ["keyword", "string"], + regex : /((?:option|button)\s+)(.*)/ + }, { + token : ["keyword", "text", "string"], + regex : /((?:sentence|text)\s+)(\S+\s*)(.*)/ + }, { + token : ["keyword", "text", "string", "invalid.illegal"], + regex : /(word\s+)(\S+\s*)(\S+)?(\s.*)?/ + }, { + token : ["keyword", "text", "constant.language"], + regex : /(boolean\s+)(\S+\s*)(0|1|"?(?:yes|no)"?)/ + }, { + token : ["keyword", "text", "constant.numeric"], + regex : /((?:real|natural|positive|integer)\s+)(\S+\s*)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/ + }, { + token : ["keyword", "string"], + regex : /(comment\s+)(.*)/ + }, { + token : "keyword", + regex : 'endform', + next : "start" + } + ], + "for" : [ + { + token : ["keyword", "text", "constant.numeric", "text"], + regex : /(from|to)(\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?)(\s*)/ + }, { + token : ["keyword", "text"], + regex : /(from|to)(\s+\S+\s*)/ }, { token : "text", - regex : "\\s+" - } - ], - "qqstring" : [ - { - token : "string", - regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"', + regex : /$/, next : "start" - }, { - token : "string", - regex : '.+' } ], - "qstring" : [ - { - token : "string", - regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'", - next : "start" - }, { - token : "string", - regex : '.+' - } - ], - "block_comment": [ - { - token: "comment.doc", - regex: "^=cut\\b", - next: "start" - }, - { - defaultToken: "comment.doc" - } - ] }; }; -oop.inherits(PerlHighlightRules, TextHighlightRules); +oop.inherits(PraatHighlightRules, TextHighlightRules); -exports.PerlHighlightRules = PerlHighlightRules; +exports.PraatHighlightRules = PraatHighlightRules; }); From 08afa03cb9c140ffe7ca86e3b5edb038b9433a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Joaqu=C3=ADn=20Atria?= Date: Tue, 3 Jun 2014 14:32:55 -0400 Subject: [PATCH 3/8] Fixed operators and introduced broken lines --- lib/ace/mode/praat_highlight_rules.js | 47 ++++++++++++++++++--------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 693a6572..0ce8a802 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -8,7 +8,7 @@ var PraatHighlightRules = function() { var keywords = ( "if|then|else|elsif|elif|endif|fi|" + - "endfor|" + // other for-related keywords are specified below + "endfor|endproc|" + // other for-related keywords are specified below "while|endwhile|" + "repeat|until|" + "select|plus|minus|" + @@ -109,6 +109,18 @@ var PraatHighlightRules = function() { this.$rules = { "start" : [ { + token : ["text", "keyword.operator", "text"], + regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/ + }, { + token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"], + regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ + }, { + token : ["text", "keyword", "text", "keyword"], + regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ + }, { + token : ["text", "keyword"], + regex : /(^\s*)(demo\b)/ + }, { token : "entity.name.type", regex : "(" + objectTypes + ")" }, { @@ -118,9 +130,6 @@ var PraatHighlightRules = function() { token : ["support.function", "text"], regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())" }, { -// token : ["keyword", "text", "keyword", "text", "keyword", "text"], -// regex : /\b(for)(\s+\S+\s*)(?:(from)(\s+[a-z][a-zA-Z0-9_.]*\$?\s*))?(?:(to)(\s+\S+\s*))?/, -// }, { token : "keyword", regex : /(\bfor\b)/, next : "for" @@ -133,6 +142,10 @@ var PraatHighlightRules = function() { }, { token : "string", regex : /"[^"]*"/ + }, { + token : "string", + regex : /"[^"]*$/, + next : "brokenstring" }, { token : ["text", "keyword", "text", "entity.name.section"], // multi line string start regex : /(^\s*)(\bform\b)(\s+)(.*)/, @@ -140,6 +153,9 @@ var PraatHighlightRules = function() { }, { token : "constant.numeric", regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { + token : ["keyword", "text", "entity.name.function"], + regex : /(procedure)(\s+)(\S+)/ }, { token : ["entity.name.function", "text"], regex : /(@\S+)(:|\s*\()/ @@ -147,17 +163,8 @@ var PraatHighlightRules = function() { token : ["text", "keyword", "text", "entity.name.function"], regex : /(^\s*)(call)(\s+)(\S+)/ }, { - token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"], - regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ - }, { - token : ["text", "keyword", "text", "keyword"], - regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ - }, { - token : ["text", "keyword"], - regex : /(^\s*)(demo\b)/ - }, { - token : "keyword.operator", - regex : /(?:\b((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)\b)/ + token : "comment", + regex : ";.*$" }, { token : "comment", regex : "#.*$" @@ -210,6 +217,16 @@ var PraatHighlightRules = function() { next : "start" } ], + "brokenstring" : [ + { + token : ["text", "string"], + regex : /(\s*\.{3})([^"]*)/ + }, { + token : "string", + regex : /"/, + next : "start" + } + ], }; }; From d57e010ca3c3bbb77a2b7104bd1837fdf3a4af9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Joaqu=C3=ADn=20Atria?= Date: Tue, 3 Jun 2014 15:10:31 -0400 Subject: [PATCH 4/8] Added single number font size changing commands (praat) --- lib/ace/mode/praat_highlight_rules.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 0ce8a802..9ba554ec 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -118,9 +118,13 @@ var PraatHighlightRules = function() { token : ["text", "keyword", "text", "keyword"], regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ }, { - token : ["text", "keyword"], - regex : /(^\s*)(demo\b)/ + token : ["text", "keyword", "text", "keyword"], + regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/ }, { + // Is this rule necessary? + // token : ["text", "keyword"], + // regex : /(^\s*)(demo\b)/ + // }, { token : "entity.name.type", regex : "(" + objectTypes + ")" }, { From a519520ae7cf18abd7a97c88665b40f4c7d962e2 Mon Sep 17 00:00:00 2001 From: baboso Date: Wed, 4 Jun 2014 18:03:55 -0400 Subject: [PATCH 5/8] Removed useless rules, added support for do() syntax --- demo/kitchen-sink/docs/praat.praat | 7 ++++--- lib/ace/mode/praat_highlight_rules.js | 19 ++++--------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/demo/kitchen-sink/docs/praat.praat b/demo/kitchen-sink/docs/praat.praat index 48a649a2..f15e4058 100644 --- a/demo/kitchen-sink/docs/praat.praat +++ b/demo/kitchen-sink/docs/praat.praat @@ -63,8 +63,8 @@ for i from 1 to n pitch = noprogress To Pitch (ac): 0, 75, 15, "no", ...0.03, 0.45, 0.01, 0.35, 0.14, 600 - # Old-style command with assignment - minimum = Get minimum... 0 0 "Hertz" Parabolic + # do-style command with assignment + minimum = do("Get minimum...", 0, 0, "Hertz", "Parabolic") # New-style multi-line command call with broken strings table = Create Table with column names: "table", 0, @@ -76,7 +76,8 @@ for i from 1 to n # Picture window commands selectObject: sound - Select inner viewport: 1, 6, 0.5, 1.5 + # do-style command + do("Select inner viewport...", 1, 6, 0.5, 1.5) Black Draw... 0 0 0 0 "no" Curve Draw inner box diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 9ba554ec..1e53b94c 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -15,8 +15,6 @@ var PraatHighlightRules = function() { "assert" ); -// var buildinConstants = ("ARGV|ENV|INC|SIG"); - var predefinedVariables = ( "macintosh|windows|unix|" + "praatVersion|praatVersion\\$" + @@ -91,18 +89,6 @@ var PraatHighlightRules = function() { "ResultsMFC|EEG|ERPTier|ERP|KNN|FeatureWeights" ); - var keywordMapper = this.createKeywordMapper({ - "keyword": keywords, -// "constant.language": buildinConstants, - "support.function": functions - }, "identifier"); - - var inlineIf = this.createKeywordMapper({ - "keyword": "(if|then|else|fi)", -// "constant.language": buildinConstants, - "support.function": functions - }, "identifier"); - // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -120,6 +106,9 @@ var PraatHighlightRules = function() { }, { token : ["text", "keyword", "text", "keyword"], regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/ + }, { + token : ["text", "support.function", "text"], + regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/ }, { // Is this rule necessary? // token : ["text", "keyword"], @@ -151,7 +140,7 @@ var PraatHighlightRules = function() { regex : /"[^"]*$/, next : "brokenstring" }, { - token : ["text", "keyword", "text", "entity.name.section"], // multi line string start + token : ["text", "keyword", "text", "entity.name.section"], regex : /(^\s*)(\bform\b)(\s+)(.*)/, next : "form" }, { From 17c75da27b040310cf1aa06a92c14fbb0d893ec1 Mon Sep 17 00:00:00 2001 From: baboso Date: Thu, 5 Jun 2014 00:45:20 -0400 Subject: [PATCH 6/8] Added sendpraat and unquoted string directives, simplified demo example, added some other missing functions/directives --- demo/kitchen-sink/docs/praat.praat | 44 ++++++++++++------ lib/ace/ext/modelist.js | 2 +- lib/ace/mode/praat.js | 1 - lib/ace/mode/praat_highlight_rules.js | 64 +++++++++++++++++++++------ 4 files changed, 81 insertions(+), 30 deletions(-) diff --git a/demo/kitchen-sink/docs/praat.praat b/demo/kitchen-sink/docs/praat.praat index f15e4058..c5dde785 100644 --- a/demo/kitchen-sink/docs/praat.praat +++ b/demo/kitchen-sink/docs/praat.praat @@ -12,6 +12,13 @@ form Highlighter test natural Nat 4 endform +# External scripts +include /path/to/file +runScript: "/path/to/file" +execute /path/to/file + +stopwatch + # old-style procedure call call oldStyle "quoted" 2 unquoted string assert oldStyle.local = 1 @@ -22,15 +29,14 @@ if praatVersion >= 5364 # New-style procedure call with colon @newStyle: "quoted", 2, "quoted string" endif -assert newStyle.local = 1 # if-block with built-in variables if windows # We are on Windows elsif unix = 1 or !macintosh - # We are on Linux + exitScript: "We are on Linux" else macintosh == 1 - # We are on Mac + exit We are on Mac endif # inline if with inline comment @@ -89,22 +95,32 @@ for i from 1 to n demo Select inner viewport... 0 100 0 100 demo Axes... 0 100 0 100 demo Paint rectangle... white 0 100 0 100 - demo Purple - demo Times - demo 24 - # The "to" in "Click to finish" should not be a keyword demo Text... 50 centre 50 half Click to finish demoWaitForInput ( ) demo Erase all - demo Select inner viewport... 0 100 0 100 - demo Axes... 0 100 0 100 - demo Paint rectangle... purple 0 100 0 100 - demo Yellow - demo Times - demo 24 - demo Text... 50 centre 50 half Finished + demo Text: 50, "centre", 50, "half", "Finished" endfor +# An old-style sendpraat block +sendpraat Praat + ...'newline$' Create Sound as pure tone... "tone" 1 0 0.4 44100 440 0.2 0.01 0.01 + ...'newline$' Play + ...'newline$' Remove + +# A new-style sendpraat block +beginSendPraat: "Praat" + Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, 440, 0.2, 0.01, 0.01 + duration = Get total duration + Remove +endSendPraat: "duration" +appendInfoLine: "The generated sound lasted for ", duration, "seconds" + +time = stopwatch +clearinfo +echo This script took +print 'time' seconds to +printline execute. + # Old-style procedure declaration procedure oldStyle .str1$ .num .str2$ .local = 1 diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index b4fbd0da..5c5552b4 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -113,7 +113,7 @@ var supportedModes = { pgSQL: ["pgsql"], PHP: ["php|phtml"], Powershell: ["ps1"], - Praat: ["praat"], + Praat: ["praat|praatscript|psc|proc"], Prolog: ["plg|prolog"], Properties: ["properties"], Protobuf: ["proto"], diff --git a/lib/ace/mode/praat.js b/lib/ace/mode/praat.js index 01d18c9a..7b100ef0 100644 --- a/lib/ace/mode/praat.js +++ b/lib/ace/mode/praat.js @@ -42,7 +42,6 @@ var Mode = function() { this.HighlightRules = PraatHighlightRules; this.$outdent = new MatchingBraceOutdent(); - this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"}); }; oop.inherits(Mode, TextMode); diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 1e53b94c..39220a52 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -8,7 +8,7 @@ var PraatHighlightRules = function() { var keywords = ( "if|then|else|elsif|elif|endif|fi|" + - "endfor|endproc|" + // other for-related keywords are specified below + "endfor|endproc|" + // related keywords specified below "while|endwhile|" + "repeat|until|" + "select|plus|minus|" + @@ -24,10 +24,16 @@ var PraatHighlightRules = function() { "temporaryDirectory\\$|defaultDirectory\\$" ); + // What is "endSendPraat"? Function? Directive? + var directives = ( + "clearinfo|endSendPraat" + ); + var functions = ( -// Math functions +// Info functions "writeInfo|writeInfoLine|appendInfo|appendInfoLine|" + "writeFile|writeFileLine|appendFile|appendFileLine|" + +// Math functions "abs|round|floor|ceiling|min|max|imin|imax|" + "sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" + "exp|ln|log10|log2|" + @@ -45,24 +51,26 @@ var PraatHighlightRules = function() { "phonToDifferenceLimens|differenceLimensToPhon|" + "beta|besselI|besselK|" + // String functions - "selected|selected$|numberOfSelected|variableExists|"+ + "selected|selected\\$|numberOfSelected|variableExists|"+ "index|rindex|startsWith|endsWith|"+ - "index_regex|rindex_regex|replace_regex$|"+ - "length|extractWord$|extractLine$|extractNumber|" + - "left$|right$|mid$|replace$|" + + "index_regex|rindex_regex|replace_regex\\$|"+ + "length|extractWord\\$|extractLine\\$|extractNumber|" + + "left\\$|right\\$|mid\\$|replace\\$|" + // Pause functions "beginPause|endPause|" + // Demo functions "demoShow|demoWindowTitle|demoInput|demoWaitForInput|" + "demoClicked|demoClickedIn|demoX|demoY|" + - "demoKeyPressed|demoKey$|" + + "demoKeyPressed|demoKey\\$|" + "demoExtraControlKeyPressed|demoShiftKeyPressed|"+ "demoCommandKeyPressed|demoOptionKeyPressed|" + // File functions - "environment$|" + - "chooseDirectory$|createDirectory|fileReadable|deleteFile|" + + "environment\\$|chooseReadFile\\$|" + + "chooseDirectory\\$|createDirectory|fileReadable|deleteFile|" + "selectObject|removeObject|plusObject|minusObject|" + - "runScript|exitScript" + "runScript|exitScript|" + +// sendpraat functions + "beginSendPraat|endSendPraat" ); var objectTypes = ( @@ -95,18 +103,35 @@ var PraatHighlightRules = function() { this.$rules = { "start" : [ { + // stopwatch + token : ["text", "text", "keyword.operator", "text", "keyword"], + regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(stopwatch)/ + }, { + // Directives which introduce unquoted strings + token : ["text", "keyword", "text", "string"], + regex : /(^\s*)(print(?:line)?|echo|exit|pause|sendpraat|include|execute)(\s+)(.*)/ + }, { + // Directives with no arguments + token : ["text", "keyword"], + regex : "(^\\s*)(" + directives + ")$" + }, { + // Operators token : ["text", "keyword.operator", "text"], regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/ }, { + // Commands token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"], regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ }, { + // Demo commands token : ["text", "keyword", "text", "keyword"], regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/ }, { + // Font-sizing commands token : ["text", "keyword", "text", "keyword"], regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/ }, { + // do-style command calls token : ["text", "support.function", "text"], regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/ }, { @@ -114,53 +139,64 @@ var PraatHighlightRules = function() { // token : ["text", "keyword"], // regex : /(^\s*)(demo\b)/ // }, { + // Object types token : "entity.name.type", regex : "(" + objectTypes + ")" }, { + // Predefined variables token : "variable.language", regex : "(" + predefinedVariables + ")" }, { + // Functions token : ["support.function", "text"], regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())" }, { + // For-loop declarations token : "keyword", regex : /(\bfor\b)/, next : "for" }, { + // Generic keywords token : "keyword", regex : "(\\b(?:" + keywords + ")\\b)" }, { + // Interpolated strings token : "string.interpolated", regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/ }, { + // Generic strings token : "string", regex : /"[^"]*"/ }, { + // Multiline quoted strings token : "string", regex : /"[^"]*$/, next : "brokenstring" }, { + // Form declarations token : ["text", "keyword", "text", "entity.name.section"], regex : /(^\s*)(\bform\b)(\s+)(.*)/, next : "form" }, { + // Numeric constants token : "constant.numeric", regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ }, { + // Procedure declarations token : ["keyword", "text", "entity.name.function"], regex : /(procedure)(\s+)(\S+)/ }, { + // New-style procedure calls token : ["entity.name.function", "text"], regex : /(@\S+)(:|\s*\()/ }, { + // Old-style procedure calls token : ["text", "keyword", "text", "entity.name.function"], regex : /(^\s*)(call)(\s+)(\S+)/ }, { + // Comments token : "comment", - regex : ";.*$" - }, { - token : "comment", - regex : "#.*$" + regex : /(^\s*#|;).*$/ }, { token : "text", regex : /\s+/ From 84a8201dfd71b191a75140fa2b1f07a12be5d47d Mon Sep 17 00:00:00 2001 From: baboso Date: Thu, 5 Jun 2014 18:44:20 -0400 Subject: [PATCH 7/8] Removed useless rule --- lib/ace/mode/praat_highlight_rules.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 39220a52..9cf98bcb 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -135,10 +135,6 @@ var PraatHighlightRules = function() { token : ["text", "support.function", "text"], regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/ }, { - // Is this rule necessary? - // token : ["text", "keyword"], - // regex : /(^\s*)(demo\b)/ - // }, { // Object types token : "entity.name.type", regex : "(" + objectTypes + ")" From 4904f74dbdcc21a0a58852f55194a81864ebf8cf Mon Sep 17 00:00:00 2001 From: baboso Date: Tue, 8 Jul 2014 15:18:57 -0400 Subject: [PATCH 8/8] Minor changes to Praat syntax files --- demo/kitchen-sink/docs/praat.praat | 16 +++++++++ lib/ace/mode/praat_highlight_rules.js | 51 ++++++++++++++------------- lib/ace/snippets/praat.js | 7 ++++ lib/ace/snippets/praat.snippets | 0 4 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 lib/ace/snippets/praat.js create mode 100644 lib/ace/snippets/praat.snippets diff --git a/demo/kitchen-sink/docs/praat.praat b/demo/kitchen-sink/docs/praat.praat index c5dde785..3700ae6f 100644 --- a/demo/kitchen-sink/docs/praat.praat +++ b/demo/kitchen-sink/docs/praat.praat @@ -59,6 +59,22 @@ for i from 1 to n selectObject(sound[i]) selectObject: sound + # Pause commands + beginPause("Viewing " + sound$) + if i > 1 + button = endPause("Stop", "Previous", + ...if i = total_sounds then "Finish" else "Next" fi, + ...3, 1) + else + button = endPause("Stop", + ...if i = total_sounds then "Finish" else "Next" fi, + ...2, 1) + endif + editor_name$ = if total_textgrids then "TextGrid " else "Sound " fi + name$ + nocheck editor 'editor_name$' + nocheck Close + nocheck endeditor + # New-style standalone command call Rename: "SomeName" diff --git a/lib/ace/mode/praat_highlight_rules.js b/lib/ace/mode/praat_highlight_rules.js index 9cf98bcb..8b826487 100644 --- a/lib/ace/mode/praat_highlight_rules.js +++ b/lib/ace/mode/praat_highlight_rules.js @@ -74,27 +74,28 @@ var PraatHighlightRules = function() { ); var objectTypes = ( - "Collection|Strings|ManPages|SortedSetOfString|Sound|Matrix|Polygon|" + - "PointProcess|ParamCurve|Spectrum|Ltas|Spectrogram|Formant|" + - "Excitation|Cochleagram|VocalTract|FormantPoint|FormantTier|" + - "FormantGrid|Label|Tier|Autosegment|Intensity|Pitch|Harmonicity|" + - "Transition|RealPoint|RealTier|PitchTier|IntensityTier|DurationTier|" + - "AmplitudeTier|SpectrumTier|Manipulation|TextPoint|TextInterval|" + - "TextTier|IntervalTier|TextGrid|LongSound|WordList|SpellingChecker|" + - "Movie|Corpus|TableOfReal|Distributions|PairDistribution|Table|" + - "LinearRegression|LogisticRegression|Art|Artword|Speaker|Activation|" + - "BarkFilter|Categories|Cepstrum|CCA|ChebyshevSeries|" + - "ClassificationTable|Confusion|Correlation|Covariance|Discriminant|" + - "DTW|Eigen|Excitations|FormantFilter|Index|KlattTable|Permutation|" + - "ISpline|LegendreSeries|MelFilter|MSpline|Pattern|PCA|Polynomial|" + - "Roots|SimpleString|StringsIndex|SpeechSynthesizer|SPINET|SSCP|SVD|" + - "AffineTransform|Procrustes|ContingencyTable|Dissimilarity|" + - "Similarity|Configuration|Distance|Salience|ScalarProduct|Weight|" + - "KlattGrid|HMM|HMM_State|HMM_Observation|HMM_ObservationSequence|" + - "HMM_StateSequence|GaussianMixture|Diagonalizer|MixingMatrix|" + - "CrossCorrelationTable|CrossCorrelationTables|Network|OTGrammar|" + - "OTHistory|OTMulti|FFNet|Cepstrumc|LPC|LFCC|MFCC|ExperimentMFC|" + - "ResultsMFC|EEG|ERPTier|ERP|KNN|FeatureWeights" + "Activation|AffineTransform|AmplitudeTier|Art|Artword|Autosegment|" + + "BarkFilter|CCA|Categories|Cepstrum|Cepstrumc|ChebyshevSeries|" + + "ClassificationTable|Cochleagram|Collection|Configuration|" + + "Confusion|ContingencyTable|Corpus|Correlation|Covariance|" + + "CrossCorrelationTable|CrossCorrelationTables|DTW|Diagonalizer|" + + "Discriminant|Dissimilarity|Distance|Distributions|DurationTier|" + + "EEG|ERP|ERPTier|Eigen|Excitation|Excitations|ExperimentMFC|FFNet|" + + "FeatureWeights|Formant|FormantFilter|FormantGrid|FormantPoint|" + + "FormantTier|GaussianMixture|HMM|HMM_Observation|" + + "HMM_ObservationSequence|HMM_State|HMM_StateSequence|Harmonicity|" + + "ISpline|Index|Intensity|IntensityTier|IntervalTier|KNN|KlattGrid|" + + "KlattTable|LFCC|LPC|Label|LegendreSeries|LinearRegression|" + + "LogisticRegression|LongSound|Ltas|MFCC|MSpline|ManPages|" + + "Manipulation|Matrix|MelFilter|MixingMatrix|Movie|Network|" + + "OTGrammar|OTHistory|OTMulti|PCA|PairDistribution|ParamCurve|" + + "Pattern|Permutation|Pitch|PitchTier|PointProcess|Polygon|" + + "Polynomial|Procrustes|RealPoint|RealTier|ResultsMFC|Roots|SPINET|" + + "SSCP|SVD|Salience|ScalarProduct|Similarity|SimpleString|" + + "SortedSetOfString|Sound|Speaker|Spectrogram|Spectrum|SpectrumTier|" + + "SpeechSynthesizer|SpellingChecker|Strings|StringsIndex|Table|" + + "TableOfReal|TextGrid|TextInterval|TextPoint|TextTier|Tier|" + + "Transition|VocalTract|Weight|WordList" ); // regexp must not have capturing parentheses. Use (?:) instead. @@ -103,6 +104,10 @@ var PraatHighlightRules = function() { this.$rules = { "start" : [ { + // Interpolated strings + token : "string.interpolated", + regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/ + }, { // stopwatch token : ["text", "text", "keyword.operator", "text", "keyword"], regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(stopwatch)/ @@ -156,10 +161,6 @@ var PraatHighlightRules = function() { token : "keyword", regex : "(\\b(?:" + keywords + ")\\b)" }, { - // Interpolated strings - token : "string.interpolated", - regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/ - }, { // Generic strings token : "string", regex : /"[^"]*"/ diff --git a/lib/ace/snippets/praat.js b/lib/ace/snippets/praat.js new file mode 100644 index 00000000..18afa87f --- /dev/null +++ b/lib/ace/snippets/praat.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./praat.snippets"); +exports.scope = "praat"; + +}); diff --git a/lib/ace/snippets/praat.snippets b/lib/ace/snippets/praat.snippets new file mode 100644 index 00000000..e69de29b