logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

applescript.lua (2836B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Applescript LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('applescript')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
  11. 'script', 'property', 'prop', 'end', 'copy', 'to', 'set', 'global', 'local', 'on', 'to', 'of',
  12. 'in', 'given', 'with', 'without', 'return', 'continue', 'tell', 'if', 'then', 'else', 'repeat',
  13. 'times', 'while', 'until', 'from', 'exit', 'try', 'error', 'considering', 'ignoring', 'timeout',
  14. 'transaction', 'my', 'get', 'put', 'into', 'is',
  15. -- References.
  16. 'each', 'some', 'every', 'whose', 'where', 'id', 'index', 'first', 'second', 'third', 'fourth',
  17. 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'last', 'front', 'back', 'st', 'nd',
  18. 'rd', 'th', 'middle', 'named', 'through', 'thru', 'before', 'after', 'beginning', 'the',
  19. -- Commands.
  20. 'close', 'copy', 'count', 'delete', 'duplicate', 'exists', 'launch', 'make', 'move', 'open',
  21. 'print', 'quit', 'reopen', 'run', 'save', 'saving',
  22. -- Operators.
  23. 'div', 'mod', 'and', 'not', 'or', 'as', 'contains', 'equal', 'equals', 'isn\'t'
  24. }, true)))
  25. -- Constants.
  26. lex:add_rule('constant', token(lexer.CONSTANT, word_match({
  27. 'case', 'diacriticals', 'expansion', 'hyphens', 'punctuation',
  28. -- Predefined variables.
  29. 'it', 'me', 'version', 'pi', 'result', 'space', 'tab', 'anything',
  30. -- Text styles.
  31. 'bold', 'condensed', 'expanded', 'hidden', 'italic', 'outline', 'plain', 'shadow',
  32. 'strikethrough', 'subscript', 'superscript', 'underline',
  33. -- Save options.
  34. 'ask', 'no', 'yes',
  35. -- Booleans.
  36. 'false', 'true',
  37. -- Date and time.
  38. 'weekday', 'monday', 'mon', 'tuesday', 'tue', 'wednesday', 'wed', 'thursday', 'thu', 'friday',
  39. 'fri', 'saturday', 'sat', 'sunday', 'sun', 'month', 'january', 'jan', 'february', 'feb', 'march',
  40. 'mar', 'april', 'apr', 'may', 'june', 'jun', 'july', 'jul', 'august', 'aug', 'september', 'sep',
  41. 'october', 'oct', 'november', 'nov', 'december', 'dec', 'minutes', 'hours', 'days', 'weeks'
  42. }, true)))
  43. -- Identifiers.
  44. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + '_')^0))
  45. -- Strings.
  46. lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
  47. -- Comments.
  48. local line_comment = lexer.to_eol('--')
  49. local block_comment = lexer.range('(*', '*)')
  50. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  51. -- Numbers.
  52. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  53. -- Operators.
  54. lex:add_rule('operator', token(lexer.OPERATOR, S('+-^*/&<>=:,(){}')))
  55. -- Fold points.
  56. lex:add_fold_point(lexer.COMMENT, '(*', '*)')
  57. lexer.property['scintillua.comment'] = '--'
  58. return lex