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

powershell.lua (2057B)


  1. -- Copyright 2015-2024 Mitchell. See LICENSE.
  2. -- PowerShell LPeg lexer.
  3. -- Contributed by Jeff Stone.
  4. local lexer = require('lexer')
  5. local token, word_match = lexer.token, lexer.word_match
  6. local P, S = lpeg.P, lpeg.S
  7. local lex = lexer.new('powershell')
  8. -- Whitespace.
  9. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  10. -- Comments.
  11. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  12. -- Keywords.
  13. lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
  14. 'Begin', 'Break', 'Continue', 'Do', 'Else', 'End', 'Exit', 'For', 'ForEach', 'ForEach-Object',
  15. 'Get-Date', 'Get-Random', 'If', 'Param', 'Pause', 'Powershell', 'Process', 'Read-Host', 'Return',
  16. 'Switch', 'While', 'Write-Host'
  17. }, true)))
  18. -- Comparison Operators.
  19. lex:add_rule('comparison', token(lexer.KEYWORD, '-' * word_match({
  20. 'and', 'as', 'band', 'bor', 'contains', 'eq', 'ge', 'gt', 'is', 'isnot', 'le', 'like', 'lt',
  21. 'match', 'ne', 'nomatch', 'not', 'notcontains', 'notlike', 'or', 'replace'
  22. }, true)))
  23. -- Parameters.
  24. lex:add_rule('parameter', token(lexer.KEYWORD, '-' *
  25. word_match('Confirm Debug ErrorAction ErrorVariable OutBuffer OutVariable Verbose WhatIf', true)))
  26. -- Properties.
  27. lex:add_rule('property', token(lexer.KEYWORD, '.' *
  28. word_match('day dayofweek dayofyear hour millisecond minute month second timeofday year', true)))
  29. -- Types.
  30. lex:add_rule('type', token(lexer.KEYWORD, '[' * word_match({
  31. 'array', 'boolean', 'byte', 'char', 'datetime', 'decimal', 'double', 'hashtable', 'int', 'long',
  32. 'single', 'string', 'xml'
  33. }, true) * ']'))
  34. -- Variables.
  35. lex:add_rule('variable', token(lexer.VARIABLE,
  36. '$' * (lexer.digit^1 + lexer.word + lexer.range('{', '}', true))))
  37. -- Strings.
  38. lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
  39. -- Numbers.
  40. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  41. -- Operators.
  42. lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*^&|~.,:;?()[]{}%`')))
  43. -- Fold points.
  44. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  45. lexer.property['scintillua.comment'] = '#'
  46. return lex