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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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+/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue