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

ini.lua (1128B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Ini 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('ini')
  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('true false on off yes no')))
  11. -- Identifiers.
  12. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
  13. -- Strings.
  14. local sq_str = lexer.range("'")
  15. local dq_str = lexer.range('"')
  16. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  17. -- Labels.
  18. lex:add_rule('label', token(lexer.LABEL, lexer.range('[', ']', true)))
  19. -- Comments.
  20. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(lexer.starts_line(S(';#')))))
  21. -- Numbers.
  22. local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
  23. lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer))
  24. -- Operators.
  25. lex:add_rule('operator', token(lexer.OPERATOR, '='))
  26. lexer.property['scintillua.comment'] = '#'
  27. return lex