Added sendpraat and unquoted string directives, simplified demo example, added some other missing functions/directives
This commit is contained in:
parent
a519520ae7
commit
17c75da27b
4 changed files with 81 additions and 30 deletions
|
|
@ -12,6 +12,13 @@ form Highlighter test
|
||||||
natural Nat 4
|
natural Nat 4
|
||||||
endform
|
endform
|
||||||
|
|
||||||
|
# External scripts
|
||||||
|
include /path/to/file
|
||||||
|
runScript: "/path/to/file"
|
||||||
|
execute /path/to/file
|
||||||
|
|
||||||
|
stopwatch
|
||||||
|
|
||||||
# old-style procedure call
|
# old-style procedure call
|
||||||
call oldStyle "quoted" 2 unquoted string
|
call oldStyle "quoted" 2 unquoted string
|
||||||
assert oldStyle.local = 1
|
assert oldStyle.local = 1
|
||||||
|
|
@ -22,15 +29,14 @@ if praatVersion >= 5364
|
||||||
# New-style procedure call with colon
|
# New-style procedure call with colon
|
||||||
@newStyle: "quoted", 2, "quoted string"
|
@newStyle: "quoted", 2, "quoted string"
|
||||||
endif
|
endif
|
||||||
assert newStyle.local = 1
|
|
||||||
|
|
||||||
# if-block with built-in variables
|
# if-block with built-in variables
|
||||||
if windows
|
if windows
|
||||||
# We are on Windows
|
# We are on Windows
|
||||||
elsif unix = 1 or !macintosh
|
elsif unix = 1 or !macintosh
|
||||||
# We are on Linux
|
exitScript: "We are on Linux"
|
||||||
else macintosh == 1
|
else macintosh == 1
|
||||||
# We are on Mac
|
exit We are on Mac
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# inline if with inline comment
|
# inline if with inline comment
|
||||||
|
|
@ -89,22 +95,32 @@ for i from 1 to n
|
||||||
demo Select inner viewport... 0 100 0 100
|
demo Select inner viewport... 0 100 0 100
|
||||||
demo Axes... 0 100 0 100
|
demo Axes... 0 100 0 100
|
||||||
demo Paint rectangle... white 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
|
demo Text... 50 centre 50 half Click to finish
|
||||||
demoWaitForInput ( )
|
demoWaitForInput ( )
|
||||||
demo Erase all
|
demo Erase all
|
||||||
demo Select inner viewport... 0 100 0 100
|
demo Text: 50, "centre", 50, "half", "Finished"
|
||||||
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
|
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
|
# Old-style procedure declaration
|
||||||
procedure oldStyle .str1$ .num .str2$
|
procedure oldStyle .str1$ .num .str2$
|
||||||
.local = 1
|
.local = 1
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ var supportedModes = {
|
||||||
pgSQL: ["pgsql"],
|
pgSQL: ["pgsql"],
|
||||||
PHP: ["php|phtml"],
|
PHP: ["php|phtml"],
|
||||||
Powershell: ["ps1"],
|
Powershell: ["ps1"],
|
||||||
Praat: ["praat"],
|
Praat: ["praat|praatscript|psc|proc"],
|
||||||
Prolog: ["plg|prolog"],
|
Prolog: ["plg|prolog"],
|
||||||
Properties: ["properties"],
|
Properties: ["properties"],
|
||||||
Protobuf: ["proto"],
|
Protobuf: ["proto"],
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ var Mode = function() {
|
||||||
this.HighlightRules = PraatHighlightRules;
|
this.HighlightRules = PraatHighlightRules;
|
||||||
|
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"});
|
|
||||||
};
|
};
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ var PraatHighlightRules = function() {
|
||||||
|
|
||||||
var keywords = (
|
var keywords = (
|
||||||
"if|then|else|elsif|elif|endif|fi|" +
|
"if|then|else|elsif|elif|endif|fi|" +
|
||||||
"endfor|endproc|" + // other for-related keywords are specified below
|
"endfor|endproc|" + // related keywords specified below
|
||||||
"while|endwhile|" +
|
"while|endwhile|" +
|
||||||
"repeat|until|" +
|
"repeat|until|" +
|
||||||
"select|plus|minus|" +
|
"select|plus|minus|" +
|
||||||
|
|
@ -24,10 +24,16 @@ var PraatHighlightRules = function() {
|
||||||
"temporaryDirectory\\$|defaultDirectory\\$"
|
"temporaryDirectory\\$|defaultDirectory\\$"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// What is "endSendPraat"? Function? Directive?
|
||||||
|
var directives = (
|
||||||
|
"clearinfo|endSendPraat"
|
||||||
|
);
|
||||||
|
|
||||||
var functions = (
|
var functions = (
|
||||||
// Math functions
|
// Info functions
|
||||||
"writeInfo|writeInfoLine|appendInfo|appendInfoLine|" +
|
"writeInfo|writeInfoLine|appendInfo|appendInfoLine|" +
|
||||||
"writeFile|writeFileLine|appendFile|appendFileLine|" +
|
"writeFile|writeFileLine|appendFile|appendFileLine|" +
|
||||||
|
// Math functions
|
||||||
"abs|round|floor|ceiling|min|max|imin|imax|" +
|
"abs|round|floor|ceiling|min|max|imin|imax|" +
|
||||||
"sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" +
|
"sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" +
|
||||||
"exp|ln|log10|log2|" +
|
"exp|ln|log10|log2|" +
|
||||||
|
|
@ -45,24 +51,26 @@ var PraatHighlightRules = function() {
|
||||||
"phonToDifferenceLimens|differenceLimensToPhon|" +
|
"phonToDifferenceLimens|differenceLimensToPhon|" +
|
||||||
"beta|besselI|besselK|" +
|
"beta|besselI|besselK|" +
|
||||||
// String functions
|
// String functions
|
||||||
"selected|selected$|numberOfSelected|variableExists|"+
|
"selected|selected\\$|numberOfSelected|variableExists|"+
|
||||||
"index|rindex|startsWith|endsWith|"+
|
"index|rindex|startsWith|endsWith|"+
|
||||||
"index_regex|rindex_regex|replace_regex$|"+
|
"index_regex|rindex_regex|replace_regex\\$|"+
|
||||||
"length|extractWord$|extractLine$|extractNumber|" +
|
"length|extractWord\\$|extractLine\\$|extractNumber|" +
|
||||||
"left$|right$|mid$|replace$|" +
|
"left\\$|right\\$|mid\\$|replace\\$|" +
|
||||||
// Pause functions
|
// Pause functions
|
||||||
"beginPause|endPause|" +
|
"beginPause|endPause|" +
|
||||||
// Demo functions
|
// Demo functions
|
||||||
"demoShow|demoWindowTitle|demoInput|demoWaitForInput|" +
|
"demoShow|demoWindowTitle|demoInput|demoWaitForInput|" +
|
||||||
"demoClicked|demoClickedIn|demoX|demoY|" +
|
"demoClicked|demoClickedIn|demoX|demoY|" +
|
||||||
"demoKeyPressed|demoKey$|" +
|
"demoKeyPressed|demoKey\\$|" +
|
||||||
"demoExtraControlKeyPressed|demoShiftKeyPressed|"+
|
"demoExtraControlKeyPressed|demoShiftKeyPressed|"+
|
||||||
"demoCommandKeyPressed|demoOptionKeyPressed|" +
|
"demoCommandKeyPressed|demoOptionKeyPressed|" +
|
||||||
// File functions
|
// File functions
|
||||||
"environment$|" +
|
"environment\\$|chooseReadFile\\$|" +
|
||||||
"chooseDirectory$|createDirectory|fileReadable|deleteFile|" +
|
"chooseDirectory\\$|createDirectory|fileReadable|deleteFile|" +
|
||||||
"selectObject|removeObject|plusObject|minusObject|" +
|
"selectObject|removeObject|plusObject|minusObject|" +
|
||||||
"runScript|exitScript"
|
"runScript|exitScript|" +
|
||||||
|
// sendpraat functions
|
||||||
|
"beginSendPraat|endSendPraat"
|
||||||
);
|
);
|
||||||
|
|
||||||
var objectTypes = (
|
var objectTypes = (
|
||||||
|
|
@ -95,18 +103,35 @@ var PraatHighlightRules = function() {
|
||||||
this.$rules = {
|
this.$rules = {
|
||||||
"start" : [
|
"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"],
|
token : ["text", "keyword.operator", "text"],
|
||||||
regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/
|
regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/
|
||||||
}, {
|
}, {
|
||||||
|
// Commands
|
||||||
token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"],
|
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}|:)))/
|
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"],
|
token : ["text", "keyword", "text", "keyword"],
|
||||||
regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
|
regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
|
||||||
}, {
|
}, {
|
||||||
|
// Font-sizing commands
|
||||||
token : ["text", "keyword", "text", "keyword"],
|
token : ["text", "keyword", "text", "keyword"],
|
||||||
regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/
|
regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/
|
||||||
}, {
|
}, {
|
||||||
|
// do-style command calls
|
||||||
token : ["text", "support.function", "text"],
|
token : ["text", "support.function", "text"],
|
||||||
regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/
|
regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -114,53 +139,64 @@ var PraatHighlightRules = function() {
|
||||||
// token : ["text", "keyword"],
|
// token : ["text", "keyword"],
|
||||||
// regex : /(^\s*)(demo\b)/
|
// regex : /(^\s*)(demo\b)/
|
||||||
// }, {
|
// }, {
|
||||||
|
// Object types
|
||||||
token : "entity.name.type",
|
token : "entity.name.type",
|
||||||
regex : "(" + objectTypes + ")"
|
regex : "(" + objectTypes + ")"
|
||||||
}, {
|
}, {
|
||||||
|
// Predefined variables
|
||||||
token : "variable.language",
|
token : "variable.language",
|
||||||
regex : "(" + predefinedVariables + ")"
|
regex : "(" + predefinedVariables + ")"
|
||||||
}, {
|
}, {
|
||||||
|
// Functions
|
||||||
token : ["support.function", "text"],
|
token : ["support.function", "text"],
|
||||||
regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())"
|
regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())"
|
||||||
}, {
|
}, {
|
||||||
|
// For-loop declarations
|
||||||
token : "keyword",
|
token : "keyword",
|
||||||
regex : /(\bfor\b)/,
|
regex : /(\bfor\b)/,
|
||||||
next : "for"
|
next : "for"
|
||||||
}, {
|
}, {
|
||||||
|
// Generic keywords
|
||||||
token : "keyword",
|
token : "keyword",
|
||||||
regex : "(\\b(?:" + keywords + ")\\b)"
|
regex : "(\\b(?:" + keywords + ")\\b)"
|
||||||
}, {
|
}, {
|
||||||
|
// Interpolated strings
|
||||||
token : "string.interpolated",
|
token : "string.interpolated",
|
||||||
regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/
|
regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/
|
||||||
}, {
|
}, {
|
||||||
|
// Generic strings
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : /"[^"]*"/
|
regex : /"[^"]*"/
|
||||||
}, {
|
}, {
|
||||||
|
// Multiline quoted strings
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : /"[^"]*$/,
|
regex : /"[^"]*$/,
|
||||||
next : "brokenstring"
|
next : "brokenstring"
|
||||||
}, {
|
}, {
|
||||||
|
// Form declarations
|
||||||
token : ["text", "keyword", "text", "entity.name.section"],
|
token : ["text", "keyword", "text", "entity.name.section"],
|
||||||
regex : /(^\s*)(\bform\b)(\s+)(.*)/,
|
regex : /(^\s*)(\bform\b)(\s+)(.*)/,
|
||||||
next : "form"
|
next : "form"
|
||||||
}, {
|
}, {
|
||||||
|
// Numeric constants
|
||||||
token : "constant.numeric",
|
token : "constant.numeric",
|
||||||
regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
|
regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
|
||||||
}, {
|
}, {
|
||||||
|
// Procedure declarations
|
||||||
token : ["keyword", "text", "entity.name.function"],
|
token : ["keyword", "text", "entity.name.function"],
|
||||||
regex : /(procedure)(\s+)(\S+)/
|
regex : /(procedure)(\s+)(\S+)/
|
||||||
}, {
|
}, {
|
||||||
|
// New-style procedure calls
|
||||||
token : ["entity.name.function", "text"],
|
token : ["entity.name.function", "text"],
|
||||||
regex : /(@\S+)(:|\s*\()/
|
regex : /(@\S+)(:|\s*\()/
|
||||||
}, {
|
}, {
|
||||||
|
// Old-style procedure calls
|
||||||
token : ["text", "keyword", "text", "entity.name.function"],
|
token : ["text", "keyword", "text", "entity.name.function"],
|
||||||
regex : /(^\s*)(call)(\s+)(\S+)/
|
regex : /(^\s*)(call)(\s+)(\S+)/
|
||||||
}, {
|
}, {
|
||||||
|
// Comments
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : ";.*$"
|
regex : /(^\s*#|;).*$/
|
||||||
}, {
|
|
||||||
token : "comment",
|
|
||||||
regex : "#.*$"
|
|
||||||
}, {
|
}, {
|
||||||
token : "text",
|
token : "text",
|
||||||
regex : /\s+/
|
regex : /\s+/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue