From 17c75da27b040310cf1aa06a92c14fbb0d893ec1 Mon Sep 17 00:00:00 2001 From: baboso Date: Thu, 5 Jun 2014 00:45:20 -0400 Subject: [PATCH] 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+/