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

ps.lua (1550B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Postscript 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('ps')
  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. 'pop', 'exch', 'dup', 'copy', 'roll', 'clear', 'count', 'mark', 'cleartomark', 'counttomark',
  12. 'exec', 'if', 'ifelse', 'for', 'repeat', 'loop', 'exit', 'stop', 'stopped', 'countexecstack',
  13. 'execstack', 'quit', 'start', 'true', 'false', 'NULL'
  14. }))
  15. -- Functions.
  16. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  17. 'add', 'div', 'idiv', 'mod', 'mul', 'sub', 'abs', 'ned', 'ceiling', 'floor', 'round', 'truncate',
  18. 'sqrt', 'atan', 'cos', 'sin', 'exp', 'ln', 'log', 'rand', 'srand', 'rrand'
  19. }))
  20. -- Identifiers.
  21. local word = (lexer.alpha + '-') * (lexer.alnum + '-')^0
  22. lex:add_rule('identifier', token(lexer.IDENTIFIER, word))
  23. -- Strings.
  24. local arrow_string = lexer.range('<', '>')
  25. local nested_string = lexer.range('(', ')', false, false, true)
  26. lex:add_rule('string', token(lexer.STRING, arrow_string + nested_string))
  27. -- Comments.
  28. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%')))
  29. -- Numbers.
  30. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  31. -- Labels.
  32. lex:add_rule('label', token(lexer.LABEL, '/' * word))
  33. -- Operators.
  34. lex:add_rule('operator', token(lexer.OPERATOR, S('[]{}')))
  35. lexer.property['scintillua.comment'] = '%'
  36. return lex