Skip to content

Commit 6148da0

Browse files
author
Monte Goulding
committed
Added LiveCode Script grammar and snippet generation from docs.
1 parent b9f97a0 commit 6148da0

7 files changed

Lines changed: 13115 additions & 1 deletion

File tree

grammars/livecodescript.cson

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# If this is your first time writing a language grammar, check out:
2+
# - http://manual.macromates.com/en/language_grammars
3+
4+
'scopeName': 'source.livecodescript'
5+
'name': 'LiveCode Script'
6+
'fileTypes': [
7+
'livecodescript'
8+
]
9+
repository:
10+
constants:
11+
patterns: [
12+
{
13+
match: "(?i)\\b(SIX|TEN|FORMFEED|NINE|ZERO|NONE|SPACE|FOUR|FALSE|COLON|CRLF|PI|COMMA|ENDOFFILE|EOF|EIGHT|FIVE|QUOTE|EMPTY|ONE|TRUE|((?<=\\w\\s)RETURN)|CR|LINEFEED|RIGHT|BACKSLASH|NULL|SEVEN|TAB|THREE|TWO)\\b"
14+
name: "constant.language.iRev"
15+
}
16+
]
17+
"function-call":
18+
match: "[A-Za-z_][A-Za-z_0-9]*(?=\\s*\\()"
19+
name: "meta.function-call.livecodescript"
20+
language:
21+
patterns: [
22+
{
23+
begin: "/\\*"
24+
captures:
25+
"0":
26+
name: "punctuation.definition.comment.livecodescript"
27+
end: "\\*/"
28+
name: "comment.block.livecodescript"
29+
}
30+
{
31+
captures:
32+
"1":
33+
name: "punctuation.definition.comment.livecodescript"
34+
match: "(--).*?($\\n?)"
35+
name: "comment.line.double-dash.livecodescript"
36+
}
37+
{
38+
captures:
39+
"1":
40+
name: "punctuation.definition.comment.livecodescript"
41+
match: "(#).*?($\\n?)"
42+
name: "comment.line.number-sign.livecodescript"
43+
}
44+
{
45+
captures:
46+
"1":
47+
name: "punctuation.definition.comment.livecodescript"
48+
match: "(//).*?($\\n?)"
49+
name: "comment.line.number-sign.livecodescript"
50+
}
51+
{
52+
match: "\\b(after|byte(s)*|codepoint(s)*|codeunit(s)*|english|segment(s)*|sentence(s)*|paragraph|the|trueWord(s)*|until|word(s)*|http|forever|descending|using|line|real8|with|seventh|for|stdout|finally|element|word|fourth|before|black|ninth|sixth|characters|chars|stderr|uInt(1|1s|2|2s)|stdin|string|lines|relative|rel|any|fifth|items|from|middle|mid|at|else|of|catch|then|third|it|file|milli(seconds|second|secs|sec)|int(1|1s|4|4s|ernet|2|2s)|normal|text|item|last|long|detailed|effective|uInt4|uInt4s|se(conds|cond|cs|c)|repeat|end\\s+repeat|URL|in|end\\s+try|into|switch|end\\s+switch|to|words|https|token|binfile|each|tenth|as|ticks|tick|system|real4|by|dateItems|without|cha(r|racter)|ascending|eighth|whole|dateTime|numeric|short|first|ftp|integer|abbreviated|abb(r|rev)|private|case|while|if|end\\s+if)\\b"
53+
name: "keyword.control.livecodescript"
54+
}
55+
{
56+
captures:
57+
"1":
58+
name: "keyword.control.exception.livecodescript"
59+
match: "\\b(catch)\\b\\s*([A-Za-z_][A-Za-z_0-9]*)"
60+
name: "meta.catch.livecodescript"
61+
}
62+
{
63+
match: "\\b(catch|try|throw)\\b"
64+
name: "keyword.control.exception.livecodescript"
65+
}
66+
{
67+
captures:
68+
"1":
69+
name: "storage.type.function.livecodescript"
70+
"2":
71+
name: "entity.name.function.livecodescript"
72+
"3":
73+
name: "variable.parameter.livecodescript"
74+
match: "(?:^\\s*)((?i)function)\\s+([A-Za-z_0-9-]+)(\\s+[A-Za-z_0-9-]+,*?\\s+.*)*"
75+
name: "meta.function.livecodescript"
76+
}
77+
{
78+
captures:
79+
"1":
80+
name: "storage.type.function.end.livecodescript"
81+
"2":
82+
name: "entity.name.end.function.livecodescript"
83+
match: "((?i)end){1}\\s+?([A-Za-z_0-9-]+)?"
84+
name: "meta.function.end.livecodescript"
85+
}
86+
{
87+
captures:
88+
"1":
89+
name: "storage.type.command.livecodescript"
90+
"2":
91+
name: "entity.name.command.livecodescript"
92+
"3":
93+
name: "variable.parameter.livecodescript"
94+
match: "(?:^\\s*)((?i)command|on)\\s+([A-Za-z_0-9-]+)(\\s+[A-Za-z_0-9-]+,*?\\s+.*)*"
95+
name: "meta.command.livecodescript"
96+
}
97+
{
98+
captures:
99+
"1":
100+
name: "storage.type.test.livecodescript"
101+
"2":
102+
name: "entity.name.test.livecodescript"
103+
match: "((?i)blah){1}\\s+?([A-Za-z_0-9-]+)?"
104+
name: "meta.test.livecodescript"
105+
}
106+
{
107+
match: "((command|on)\\s+([A-Za-z_0-9-]+))"
108+
name: "meta.testA.livecodescript"
109+
}
110+
{
111+
match: "(\\-|\\+|\\*|/|%)"
112+
name: "keyword.operator.arithmetic.livecodescript"
113+
}
114+
{
115+
match: "(?i)\\b(and|or)\\b"
116+
name: "keyword.operator.logical.livecodescript"
117+
}
118+
{
119+
match: "(?i)\\b(bitAnd|bitNot|bitOr|bitXor)\\b"
120+
name: "keyword.operator.bitwise.livecodescript"
121+
}
122+
{
123+
match: "(?i)(=|<>|>=|<=|<|>)|\\b(is( among| not among| not in| a| an| not| in| not within| within| not a| not an)*|there is( no| not a| not an| a| an)|contains|ends with|begins with|is among the keys of|is not among the keys of)\\b"
124+
name: "keyword.operator.comparison.livecodescript"
125+
}
126+
{
127+
match: "(&|&&)"
128+
name: "keyword.operator.string.livecodescript"
129+
}
130+
{
131+
match: "(\\^)|\\b(div|mod|wrap)\\b"
132+
name: "keyword.operator.other.livecodescript"
133+
}
134+
{
135+
match: "(\\^)|\\b(abs|acos|aliasReference|annuity|arrayDecode|arrayEncode|asin|atan(2)*|average(Deviation)*|avg(Dev)*|base64Decode|base64Encode|baseConvert|binaryDecode|binaryEncode|byte(Offset|ToNum)+|cachedURL(s)*|charToNum|cipherNames|codepoint(Offset|Property|ToNum)+|codeunitOffset|commandNames|compound|compress|constantNames|cos|date(Format)*|decompress|directories|diskSpace|DNSServers|exp(1|2|10)*|extents|files|flushEvents|folders|format|functionNames|geometricMean|global(s|Names)+|harmonicMean|hasMemory|hostAddress|hostAddressToName|hostName(ToAddress)*|isNumber|ISOToMac|itemOffset|keys|len(gth)*|libURLErrorData|libUrlFormData|libURLftpCommand|libURLLastHTTPHeaders|libURLLastRHHeaders|libUrlMultipartFormAddPart|libUrlMultipartFormData|libURLVersion|lineOffset|ln(1)*|localNames|log(2|10)*|longFilePath|lower|macToISO|matchChunk|matchText|matrixMultiply|max|md5Digest|median|merge|milli(sec|secs|second|seconds)+|min|monthNames|nativeCharToNum|normalizeText|num(ber|ToByte|ToChar|ToCodepoint|ToNativeChar)*|offset|open(files|Processes)*|openProcessIDs|openSockets|paragraphOffset|paramCount|param(s)*|peerAddress|pendingMessages|platform|popStdDev|populationStandardDeviation|popVariance|populationVariance|processID|random(Bytes)*|replaceText|result|revCreateXMLTree|revCreateXMLTreeFromFile|revCurrentRecord|revCurrentRecordIsFirst|revCurrentRecordIsLast|revDatabaseColumnCount|revDatabaseColumnIsNull|revDatabaseColumnLengths|revDatabaseColumnName(s|d)+|revDatabaseColumnNumbered|revDatabaseColumnTypes|revDatabaseConnectResult|revDatabaseCursors|revDatabaseID|revDatabaseTableNames|revDatabaseType|revDataFromQuery|revdb_closeCursor|revdb_columnbynumber|revdb_columncount|revdb_columnisnull|revdb_columnlengths|revdb_columnnames|revdb_columntypes|revdb_commit|revdb_connect(ions)*|revdb_connectionerr|revdb_currentrecord|revdb_cursorconnection|revdb_cursorerr|revdb_cursors|revdb_dbtype|revdb_disconnect|revdb_execute|revdb_is(eof|bof)+|revdb_movefirst|revdb_movelast|revdb_movenext|revdb_moveprev|revdb_query|revdb_querylist|revdb_recordcount|revdb_rollback|revdb_tablenames|revGetDatabaseDriverPath|revNumberOfRecords|revOpenDatabase(s)*|revQueryDatabase(Blob)*|revQuery(Result|IsAtStart|IsAtEnd)+|revUnixFromMacPath|revXMLAttribute(s)*|revXMLAttributeValues|revXMLChildContents|revXMLChildNames|revXMLCreateTreeFromFileWithNamespaces|revXMLCreateTreeWithNamespaces|revXMLDataFromXPathQuery|revXMLEvaluateXPath|revXMLFirstChild|revXMLMatchingNode|revXMLNextSibling|revXMLNodeContents|revXMLNumberOfChildren|revXMLParent|revXMLPreviousSibling|revXMLRootNode|revXMLRPC_CreateRequest|revXMLRPC_Documents|revXMLRPC_Error|revXMLRPC_Execute|revXMLRPC_GetHost|revXMLRPC_GetMethod|revXMLRPC_GetParam|revXMLText|revXMLRPC_GetParamCount|revXMLRPC_GetParamNode|revXMLRPC_GetParamType|revXMLRPC_GetPath|revXMLRPC_GetPort|revXMLRPC_GetProtocol|revXMLRPC_GetRequest|revXMLRPC_GetResponse|revXMLRPC_GetSocket|revXMLTree(s)*|revXMLValidateDTD|revZipDescribeItem|revZipEnumerateItems|revZipOpenArchives|round|sampVariance|sec(s|onds)*|sentenceOffset|sha1Digest|shell|shortFilePath|sin|specialFolderPath|sqrt|standardDeviation|statRound|stdDev|sum|sysError|systemVersion|tan|tempName|textDecode|textEncode|tick(s)*|time|to(Lower|Upper)*|tokenOffset|transpose|truewordOffset|trunc|uniDecode|uniEncode|upper|urlDecode|urlEncode|urlStatus|uuid|value|variableNames|variance|version|waitDepth|weekdayNames|wordOffset|xsltApplyStylesheet|xsltApplyStylesheetFromFile|xsltLoadStylesheet|xsltLoadStylesheetFromFile)\\b"
136+
name: "storage.type.fctn.livecodescript"
137+
}
138+
{
139+
match: "(\\^)|\\b(add|breakpoint|cancel|clear( local| global| variable| file| word| line| folder| directory| URL)*|close( file| socket| process)*|combine|constant|convert|(create|new)( alias| folder| directory)*|decrypt( using rsa)*|delete( directory| file| folder| global| line| local| session| URL| variable| word)*|dispatch|divide|do|encrypt( using rsa)*|filter|get|global|include|intersect|kill|libURLDownloadToFile|libURLFollowHttpRedirects|libURLftpUpload(File)*|libURLresetAll|libUrlSetAuthCallback|libURLSetCustomHTTPHeaders|libUrlSetExpect100|libURLSetFTPListCommand|libURLSetFTPMode|libURLSetFTPStopTime|libURLSetStatusCallback|load URL|local|multiply|open( socket| file| process)*|post|prepare|put( binary| content| cookie| header| markup| unicode)*|read( from process| from socket| from file)*|rename|replace|require|resetAll|resolve|revAddXMLNode|revAppendXML|revCloseCursor|revCloseDatabase|revCommitDatabase|revCopyFile|revCopyFolder|revCopyXMLNode|revDeleteFolder|revDeleteXMLNode|revDeleteAllXMLTrees|revDeleteXMLTree|revExecuteSQL|revGoURL|revInsertXMLNode|revMoveFolder|revMoveToFirstRecord|revMoveToLastRecord|revMoveToNextRecord|revMoveToPreviousRecord|revMoveToRecord|revMoveXMLNode|revPutIntoXMLNode|revRollBackDatabase|revSetDatabaseDriverPath|revSetXMLAttribute|revXMLRPC_AddParam|revXMLRPC_DeleteAllDocuments|revXMLAddDTD|revXMLRPC_Free|revXMLRPC_FreeAll|revXMLRPC_DeleteDocument|revXMLRPC_DeleteParam|revXMLRPC_SetHost|revXMLRPC_SetMethod|revXMLRPC_SetPort|revXMLRPC_SetProtocol|revXMLRPC_SetSocket|revZipAddItemWithData|revZipAddItemWithFile|revZipAddUncompressedItemWithData|revZipAddUncompressedItemWithFile|revZipCancel|revZipCloseArchive|revZipDeleteItem|revZipExtractItemToFile|revZipExtractItemToVariable|revZipSetProgressCallback|revZipRenameItem|revZipReplaceItemWithData|revZipReplaceItemWithFile|revZipOpenArchive|seek( to| rel| relative)*|send|set|sort|split|start( session)*|stop( session)*|subtract|union|unload( URL)*|wait|write)\\b"
140+
name: "storage.type.comnd.livecodescript"
141+
}
142+
{
143+
include: "#constants"
144+
}
145+
{
146+
include: "#support"
147+
}
148+
{
149+
include: "#numbers"
150+
}
151+
{
152+
include: "#strings"
153+
}
154+
{
155+
include: "#variables"
156+
}
157+
]
158+
numbers:
159+
match: "\\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)\\b"
160+
name: "constant.numeric.livecodescript"
161+
"string-quoted":
162+
begin: "\""
163+
beginCaptures:
164+
"0":
165+
name: "punctuation.definition.string.begin.livecodescript"
166+
contentName: "meta.string-contents.quoted.double.livecodescript"
167+
end: "\""
168+
endCaptures:
169+
"0":
170+
name: "punctuation.definition.string.end.livecodescript"
171+
name: "string.quoted.double.livecodescript"
172+
patterns: [
173+
{
174+
include: "#interpolation"
175+
}
176+
]
177+
strings:
178+
patterns: [
179+
{
180+
include: "#string-quoted"
181+
}
182+
]
183+
var_global:
184+
captures:
185+
"1":
186+
name: "punctuation.definition.variable.livecodescript"
187+
match: "\\b(g)[A-Z]{1}.*?\\b"
188+
name: "variable.other.global.livecodescript"
189+
var_local:
190+
captures:
191+
"1":
192+
name: "punctuation.definition.variable.livecodescript"
193+
match: "\\b(t)[A-Z]{1}.*?\\b"
194+
name: "variable.other.global.livecodescript"
195+
var_parameter:
196+
captures:
197+
"1":
198+
name: "punctuation.definition.variable.livecodescript"
199+
match: "\\b(p)[A-Z]{1}.*?\\b"
200+
name: "variable.parameter.livecodescript"
201+
var_scriptLocal:
202+
captures:
203+
"1":
204+
name: "punctuation.definition.variable.livecodescript"
205+
match: "\\b(s)[A-Z]{1}.*?\\b"
206+
name: "variable.other.global.livecodescript"
207+
var_server:
208+
match: "\\$_[A-Z]+"
209+
name: "variable.other.server.livecodescript"
210+
variables:
211+
patterns: [
212+
{
213+
include: "#var_global"
214+
}
215+
{
216+
include: "#var_scriptLocal"
217+
}
218+
{
219+
include: "#var_local"
220+
}
221+
{
222+
include: "#var_parameter"
223+
}
224+
{
225+
include: "#var_server"
226+
}
227+
]

settings/language-livecode.cson

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,13 @@
703703
"$_POST_RAW"
704704
]
705705
commentStart: "-- "
706+
707+
# LiveCode Script
708+
#################
709+
710+
".source.livecodescript":
711+
'editor':
712+
'increaseIndentPattern': "(^on\\s+?.+)|(^command\\s+?.+)|(^function\\s+?.+)|(\\s*if\\s+?.+)|(\\s*else)|(\\s*repeat\\s+?.+)|(switch\\s+?.+)|(case\\s+?.+)|(\\s*(?<!end )try$)|(\\s*catch\\s+?.+)"
713+
'decreaseIndentPattern': "(\\s*end\\s+?.+)|(\\s*break$)|(\\s*else$)|(\\s*catch\\s+?.+)"
714+
'tabLength': 3
715+
'foldEndPattern': '^\\s*end\\b'

0 commit comments

Comments
 (0)