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

json.lua (721B)


  1. -- Copyright 2006-2024 Brian "Sir Alaran" Schott. See LICENSE.
  2. -- JSON LPeg lexer.
  3. -- Based off of lexer code by Mitchell.
  4. local lexer = lexer
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new(...)
  7. -- Strings.
  8. local sq_str = lexer.range("'", true)
  9. local dq_str = lexer.range('"', true)
  10. lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
  11. -- Keywords.
  12. lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.word_match('true false null')))
  13. -- Numbers.
  14. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
  15. -- Operators.
  16. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('[]{}:,')))
  17. -- Fold points.
  18. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  19. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  20. return lex