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

pike.lua (1748B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Pike 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('pike')
  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. 'break', 'case', 'catch', 'continue', 'default', 'do', 'else', 'for', 'foreach', 'gauge', 'if',
  12. 'lambda', 'return', 'sscanf', 'switch', 'while', 'import', 'inherit',
  13. -- Type modifiers.
  14. 'constant', 'extern', 'final', 'inline', 'local', 'nomask', 'optional', 'private', 'protected',
  15. 'public', 'static', 'variant'
  16. }))
  17. -- Types.
  18. lex:add_rule('type', token(lexer.TYPE, word_match(
  19. 'array class float function int mapping mixed multiset object program string void')))
  20. -- Identifiers.
  21. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  22. -- Strings.
  23. local sq_str = lexer.range("'", true)
  24. local dq_str = P('#')^-1 * lexer.range('"', true)
  25. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  26. -- Comments.
  27. local line_comment = lexer.to_eol('//', true)
  28. local block_comment = lexer.range('/*', '*/', false, false, true)
  29. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  30. -- Numbers.
  31. lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('lLdDfF')^-1))
  32. -- Preprocessors.
  33. lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, lexer.to_eol(lexer.starts_line('#'))))
  34. -- Operators.
  35. lex:add_rule('operator', token(lexer.OPERATOR, S('<>=!+-/*%&|^~@`.,:;()[]{}')))
  36. -- Fold points.
  37. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  38. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  39. lexer.property['scintillua.comment'] = '//'
  40. return lex