PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/rouge/lexers/apple_script.rb

https://github.com/knutaldrin/rouge
Ruby | 366 lines | 355 code | 10 blank | 1 comment | 0 complexity | 79b4b53d82ee4e7a60a2c3be045e3105 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. # -*- coding: utf-8 -*- #
  2. module Rouge
  3. module Lexers
  4. class AppleScript < RegexLexer
  5. desc "The AppleScript scripting language by Apple Inc. (http://developer.apple.com/applescript/)"
  6. tag 'applescript'
  7. aliases 'applescript'
  8. filenames '*.applescript', '*.scpt'
  9. mimetypes 'application/x-applescript'
  10. def self.literals
  11. @literals ||= ['AppleScript', 'current application', 'false', 'linefeed',
  12. 'missing value', 'pi','quote', 'result', 'return', 'space',
  13. 'tab', 'text item delimiters', 'true', 'version']
  14. end
  15. def self.classes
  16. @classes ||= ['alias ', 'application ', 'boolean ', 'class ', 'constant ',
  17. 'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
  18. 'real ', 'record ', 'reference ', 'RGB color ', 'script ',
  19. 'text ', 'unit types', '(?:Unicode )?text', 'string']
  20. end
  21. def self.builtins
  22. @builtins ||= ['attachment', 'attribute run', 'character', 'day', 'month',
  23. 'paragraph', 'word', 'year']
  24. end
  25. def self.handler_params
  26. @handler_params ||= ['about', 'above', 'against', 'apart from', 'around',
  27. 'aside from', 'at', 'below', 'beneath', 'beside',
  28. 'between', 'for', 'given', 'instead of', 'on', 'onto',
  29. 'out of', 'over', 'since']
  30. end
  31. def self.commands
  32. @commands ||= ['ASCII (character|number)', 'activate', 'beep', 'choose URL',
  33. 'choose application', 'choose color', 'choose file( name)?',
  34. 'choose folder', 'choose from list',
  35. 'choose remote application', 'clipboard info',
  36. 'close( access)?', 'copy', 'count', 'current date', 'delay',
  37. 'delete', 'display (alert|dialog)', 'do shell script',
  38. 'duplicate', 'exists', 'get eof', 'get volume settings',
  39. 'info for', 'launch', 'list (disks|folder)', 'load script',
  40. 'log', 'make', 'mount volume', 'new', 'offset',
  41. 'open( (for access|location))?', 'path to', 'print', 'quit',
  42. 'random number', 'read', 'round', 'run( script)?',
  43. 'say', 'scripting components',
  44. 'set (eof|the clipboard to|volume)', 'store script',
  45. 'summarize', 'system attribute', 'system info',
  46. 'the clipboard', 'time to GMT', 'write', 'quoted form']
  47. end
  48. def self.references
  49. @references ||= ['(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
  50. 'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
  51. 'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
  52. 'before', 'behind', 'every', 'front', 'index', 'last',
  53. 'middle', 'some', 'that', 'through', 'thru', 'where', 'whose']
  54. end
  55. def self.operators
  56. @operators ||= ["and", "or", "is equal", "equals", "(is )?equal to", "is not",
  57. "isn't", "isn't equal( to)?", "is not equal( to)?",
  58. "doesn't equal", "does not equal", "(is )?greater than",
  59. "comes after", "is not less than or equal( to)?",
  60. "isn't less than or equal( to)?", "(is )?less than",
  61. "comes before", "is not greater than or equal( to)?",
  62. "isn't greater than or equal( to)?",
  63. "(is )?greater than or equal( to)?", "is not less than",
  64. "isn't less than", "does not come before",
  65. "doesn't come before", "(is )?less than or equal( to)?",
  66. "is not greater than", "isn't greater than",
  67. "does not come after", "doesn't come after", "starts? with",
  68. "begins? with", "ends? with", "contains?", "does not contain",
  69. "doesn't contain", "is in", "is contained by", "is not in",
  70. "is not contained by", "isn't contained by", "div", "mod",
  71. "not", "(a )?(ref( to)?|reference to)", "is", "does"]
  72. end
  73. def self.controls
  74. @controls ||= ['considering', 'else', 'error', 'exit', 'from', 'if',
  75. 'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
  76. 'try', 'until', 'using terms from', 'while', 'whith',
  77. 'with timeout( of)?', 'with transaction', 'by', 'continue',
  78. 'end', 'its?', 'me', 'my', 'return', 'of' , 'as']
  79. end
  80. def self.declarations
  81. @declarations ||= ['global', 'local', 'prop(erty)?', 'set', 'get']
  82. end
  83. def self.reserved
  84. @reserved ||= ['but', 'put', 'returning', 'the']
  85. end
  86. def self.studio_classes
  87. @studio_classes ||= ['action cell', 'alert reply', 'application', 'box',
  88. 'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
  89. 'clip view', 'color well', 'color-panel',
  90. 'combo box( item)?', 'control',
  91. 'data( (cell|column|item|row|source))?', 'default entry',
  92. 'dialog reply', 'document', 'drag info', 'drawer',
  93. 'event', 'font(-panel)?', 'formatter',
  94. 'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
  95. 'movie( view)?', 'open-panel', 'outline view', 'panel',
  96. 'pasteboard', 'plugin', 'popup button',
  97. 'progress indicator', 'responder', 'save-panel',
  98. 'scroll view', 'secure text field( cell)?', 'slider',
  99. 'sound', 'split view', 'stepper', 'tab view( item)?',
  100. 'table( (column|header cell|header view|view))',
  101. 'text( (field( cell)?|view))?', 'toolbar( item)?',
  102. 'user-defaults', 'view', 'window']
  103. end
  104. def self.studio_events
  105. @studio_events ||= ['accept outline drop', 'accept table drop', 'action',
  106. 'activated', 'alert ended', 'awake from nib', 'became key',
  107. 'became main', 'begin editing', 'bounds changed',
  108. 'cell value', 'cell value changed', 'change cell value',
  109. 'change item value', 'changed', 'child of item',
  110. 'choose menu item', 'clicked', 'clicked toolbar item',
  111. 'closed', 'column clicked', 'column moved',
  112. 'column resized', 'conclude drop', 'data representation',
  113. 'deminiaturized', 'dialog ended', 'document nib name',
  114. 'double clicked', 'drag( (entered|exited|updated))?',
  115. 'drop', 'end editing', 'exposed', 'idle', 'item expandable',
  116. 'item value', 'item value changed', 'items changed',
  117. 'keyboard down', 'keyboard up', 'launched',
  118. 'load data representation', 'miniaturized', 'mouse down',
  119. 'mouse dragged', 'mouse entered', 'mouse exited',
  120. 'mouse moved', 'mouse up', 'moved',
  121. 'number of browser rows', 'number of items',
  122. 'number of rows', 'open untitled', 'opened', 'panel ended',
  123. 'parameters updated', 'plugin loaded', 'prepare drop',
  124. 'prepare outline drag', 'prepare outline drop',
  125. 'prepare table drag', 'prepare table drop',
  126. 'read from file', 'resigned active', 'resigned key',
  127. 'resigned main', 'resized( sub views)?',
  128. 'right mouse down', 'right mouse dragged',
  129. 'right mouse up', 'rows changed', 'scroll wheel',
  130. 'selected tab view item', 'selection changed',
  131. 'selection changing', 'should begin editing',
  132. 'should close', 'should collapse item',
  133. 'should end editing', 'should expand item',
  134. 'should open( untitled)?',
  135. 'should quit( after last window closed)?',
  136. 'should select column', 'should select item',
  137. 'should select row', 'should select tab view item',
  138. 'should selection change', 'should zoom', 'shown',
  139. 'update menu item', 'update parameters',
  140. 'update toolbar item', 'was hidden', 'was miniaturized',
  141. 'will become active', 'will close', 'will dismiss',
  142. 'will display browser cell', 'will display cell',
  143. 'will display item cell', 'will display outline cell',
  144. 'will finish launching', 'will hide', 'will miniaturize',
  145. 'will move', 'will open', 'will pop up', 'will quit',
  146. 'will resign active', 'will resize( sub views)?',
  147. 'will select tab view item', 'will show', 'will zoom',
  148. 'write to file', 'zoomed']
  149. end
  150. def self.studio_commands
  151. @studio_commands ||= ['animate', 'append', 'call method', 'center',
  152. 'close drawer', 'close panel', 'display',
  153. 'display alert', 'display dialog', 'display panel', 'go',
  154. 'hide', 'highlight', 'increment', 'item for',
  155. 'load image', 'load movie', 'load nib', 'load panel',
  156. 'load sound', 'localized string', 'lock focus', 'log',
  157. 'open drawer', 'path for', 'pause', 'perform action',
  158. 'play', 'register', 'resume', 'scroll', 'select( all)?',
  159. 'show', 'size to fit', 'start', 'step back',
  160. 'step forward', 'stop', 'synchronize', 'unlock focus',
  161. 'update']
  162. end
  163. def self.studio_properties
  164. @studio_properties ||= ['accepts arrow key', 'action method', 'active',
  165. 'alignment', 'allowed identifiers',
  166. 'allows branch selection', 'allows column reordering',
  167. 'allows column resizing', 'allows column selection',
  168. 'allows customization', 'allows editing text attributes',
  169. 'allows empty selection', 'allows mixed state',
  170. 'allows multiple selection', 'allows reordering',
  171. 'allows undo', 'alpha( value)?', 'alternate image',
  172. 'alternate increment value', 'alternate title',
  173. 'animation delay', 'associated file name',
  174. 'associated object', 'auto completes', 'auto display',
  175. 'auto enables items', 'auto repeat', 'auto resizes( outline column)?',
  176. 'auto save expanded items', 'auto save name',
  177. 'auto save table columns', 'auto saves configuration',
  178. 'auto scroll', 'auto sizes all columns to fit',
  179. 'auto sizes cells', 'background color', 'bezel state',
  180. 'bezel style', 'bezeled', 'border rect', 'border type',
  181. 'bordered', 'bounds( rotation)?', 'box type',
  182. 'button returned', 'button type',
  183. 'can choose directories', 'can choose files', 'can draw', 'can hide',
  184. 'cell( (background color|size|type))?', 'characters',
  185. 'class', 'click count', 'clicked( data)? column',
  186. 'clicked data item', 'clicked( data)? row',
  187. 'closeable', 'collating', 'color( (mode|panel))',
  188. 'command key down', 'configuration',
  189. 'content(s| (size|view( margins)?))?', 'context',
  190. 'continuous', 'control key down', 'control size',
  191. 'control tint', 'control view',
  192. 'controller visible', 'coordinate system',
  193. 'copies( on scroll)?', 'corner view', 'current cell',
  194. 'current column', 'current( field)? editor',
  195. 'current( menu)? item', 'current row',
  196. 'current tab view item', 'data source',
  197. 'default identifiers', 'delta (x|y|z)',
  198. 'destination window', 'directory', 'display mode',
  199. 'displayed cell', 'document( (edited|rect|view))?',
  200. 'double value', 'dragged column', 'dragged distance',
  201. 'dragged items', 'draws( cell)? background',
  202. 'draws grid', 'dynamically scrolls', 'echos bullets',
  203. 'edge', 'editable', 'edited( data)? column',
  204. 'edited data item', 'edited( data)? row', 'enabled',
  205. 'enclosing scroll view', 'ending page',
  206. 'error handling', 'event number', 'event type',
  207. 'excluded from windows menu', 'executable path',
  208. 'expanded', 'fax number', 'field editor', 'file kind',
  209. 'file name', 'file type', 'first responder',
  210. 'first visible column', 'flipped', 'floating',
  211. 'font( panel)?', 'formatter', 'frameworks path',
  212. 'frontmost', 'gave up', 'grid color', 'has data items',
  213. 'has horizontal ruler', 'has horizontal scroller',
  214. 'has parent data item', 'has resize indicator',
  215. 'has shadow', 'has sub menu', 'has vertical ruler',
  216. 'has vertical scroller', 'header cell', 'header view',
  217. 'hidden', 'hides when deactivated', 'highlights by',
  218. 'horizontal line scroll', 'horizontal page scroll',
  219. 'horizontal ruler view', 'horizontally resizable',
  220. 'icon image', 'id', 'identifier',
  221. 'ignores multiple clicks',
  222. 'image( (alignment|dims when disabled|frame style|scaling))?',
  223. 'imports graphics', 'increment value',
  224. 'indentation per level', 'indeterminate', 'index',
  225. 'integer value', 'intercell spacing', 'item height',
  226. 'key( (code|equivalent( modifier)?|window))?',
  227. 'knob thickness', 'label', 'last( visible)? column',
  228. 'leading offset', 'leaf', 'level', 'line scroll',
  229. 'loaded', 'localized sort', 'location', 'loop mode',
  230. 'main( (bunde|menu|window))?', 'marker follows cell',
  231. 'matrix mode', 'maximum( content)? size',
  232. 'maximum visible columns',
  233. 'menu( form representation)?', 'miniaturizable',
  234. 'miniaturized', 'minimized image', 'minimized title',
  235. 'minimum column width', 'minimum( content)? size',
  236. 'modal', 'modified', 'mouse down state',
  237. 'movie( (controller|file|rect))?', 'muted', 'name',
  238. 'needs display', 'next state', 'next text',
  239. 'number of tick marks', 'only tick mark values',
  240. 'opaque', 'open panel', 'option key down',
  241. 'outline table column', 'page scroll', 'pages across',
  242. 'pages down', 'palette label', 'pane splitter',
  243. 'parent data item', 'parent window', 'pasteboard',
  244. 'path( (names|separator))?', 'playing',
  245. 'plays every frame', 'plays selection only', 'position',
  246. 'preferred edge', 'preferred type', 'pressure',
  247. 'previous text', 'prompt', 'properties',
  248. 'prototype cell', 'pulls down', 'rate',
  249. 'released when closed', 'repeated',
  250. 'requested print time', 'required file type',
  251. 'resizable', 'resized column', 'resource path',
  252. 'returns records', 'reuses columns', 'rich text',
  253. 'roll over', 'row height', 'rulers visible',
  254. 'save panel', 'scripts path', 'scrollable',
  255. 'selectable( identifiers)?', 'selected cell',
  256. 'selected( data)? columns?', 'selected data items?',
  257. 'selected( data)? rows?', 'selected item identifier',
  258. 'selection by rect', 'send action on arrow key',
  259. 'sends action when done editing', 'separates columns',
  260. 'separator item', 'sequence number', 'services menu',
  261. 'shared frameworks path', 'shared support path',
  262. 'sheet', 'shift key down', 'shows alpha',
  263. 'shows state by', 'size( mode)?',
  264. 'smart insert delete enabled', 'sort case sensitivity',
  265. 'sort column', 'sort order', 'sort type',
  266. 'sorted( data rows)?', 'sound', 'source( mask)?',
  267. 'spell checking enabled', 'starting page', 'state',
  268. 'string value', 'sub menu', 'super menu', 'super view',
  269. 'tab key traverses cells', 'tab state', 'tab type',
  270. 'tab view', 'table view', 'tag', 'target( printer)?',
  271. 'text color', 'text container insert',
  272. 'text container origin', 'text returned',
  273. 'tick mark position', 'time stamp',
  274. 'title(d| (cell|font|height|position|rect))?',
  275. 'tool tip', 'toolbar', 'trailing offset', 'transparent',
  276. 'treat packages as directories', 'truncated labels',
  277. 'types', 'unmodified characters', 'update views',
  278. 'use sort indicator', 'user defaults',
  279. 'uses data source', 'uses ruler', 'uses threaded animation',
  280. 'uses title from previous column', 'value wraps', 'version',
  281. 'vertical( (line scroll|page scroll|ruler view))?', 'vertically resizable', 'view',
  282. 'visible( document rect)?', 'volume', 'width', 'window',
  283. 'windows menu', 'wraps', 'zoomable', 'zoomed']
  284. end
  285. operators = %r(\b(#{self.operators.to_a.join('|')})\b)
  286. classes = %r(\b(as )(#{self.classes.to_a.join('|')})\b)
  287. literals = %r(\b(#{self.literals.to_a.join('|')})\b)
  288. commands = %r(\b(#{self.commands.to_a.join('|')})\b)
  289. controls = %r(\b(#{self.controls.to_a.join('|')})\b)
  290. declarations = %r(\b(#{self.declarations.to_a.join('|')})\b)
  291. reserved = %r(\b(#{self.reserved.to_a.join('|')})\b)
  292. builtins = %r(\b(#{self.builtins.to_a.join('|')})s?\b)
  293. handler_params = %r(\b(#{self.handler_params.to_a.join('|')})\b)
  294. references = %r(\b(#{self.references.to_a.join('|')})\b)
  295. studio_properties = %r(\b(#{self.studio_properties.to_a.join('|')})\b)
  296. studio_classes = %r(\b(#{self.studio_classes.to_a.join('|')})s?\b)
  297. studio_commands = %r(\b(#{self.studio_commands.to_a.join('|')})\b)
  298. identifiers = %r(\b([a-zA-Z]\w*)\b)
  299. state :root do
  300. rule /\s+/, Text::Whitespace
  301. rule /¬\n/, Literal::String::Escape
  302. rule /'s\s+/, Text
  303. rule /(--|#).*?$/, Comment::Single
  304. rule /\(\*/, Comment::Multiline
  305. rule /[\(\){}!,.:]/, Punctuation
  306. rule /(«)([^»]+)(»)/ do |match|
  307. token Text, match[1]
  308. token Name::Builtin, match[2]
  309. token Text, match[3]
  310. end
  311. rule /\b((?:considering|ignoring)\s*)(application responses|case|diacriticals|hyphens|numeric strings|punctuation|white space)/ do |match|
  312. token Keyword, match[1]
  313. token Name::Builtin, match[2]
  314. end
  315. rule /(-|\*|\+|&||>=?|<=?|=|||\/|÷|\^)/, Operator
  316. rule operators, Operator::Word
  317. rule /^(\s*(?:on|end)\s+)'r'(%s)/ do |match|
  318. token Keyword, match[1]
  319. token Name::Function, match[2]
  320. end
  321. rule /^(\s*)(in|on|script|to)(\s+)/ do |match|
  322. token Text, match[1]
  323. token Keyword, match[2]
  324. token Text, match[3]
  325. end
  326. rule classes do |match|
  327. token Keyword, match[1]
  328. token Name::Class, match[2]
  329. end
  330. rule commands, Name::Builtin
  331. rule controls, Keyword
  332. rule declarations, Keyword
  333. rule reserved, Name::Builtin
  334. rule builtins, Name::Builtin
  335. rule handler_params, Name::Builtin
  336. rule studio_properties, Name::Attribute
  337. rule studio_classes, Name::Builtin
  338. rule studio_commands, Name::Builtin
  339. rule references, Name::Builtin
  340. rule /"(\\\\|\\"|[^"])*"/, Literal::String::Double
  341. rule identifiers, Name::Variable
  342. rule /[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?/, Literal::Number::Float
  343. rule /[-+]?\d+/, Literal::Number::Integer
  344. end
  345. end
  346. end
  347. end