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

batch.lua (1957B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Batch 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('batch', {case_insensitive_fold_points = true})
  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. 'cd', 'chdir', 'md', 'mkdir', 'cls', 'for', 'if', 'echo', 'echo.', 'move', 'copy', 'ren', 'del',
  12. 'set', 'call', 'exit', 'setlocal', 'shift', 'endlocal', 'pause', 'defined', 'exist', 'errorlevel',
  13. 'else', 'in', 'do', 'NUL', 'AUX', 'PRN', 'not', 'goto', 'pushd', 'popd'
  14. }, true)))
  15. -- Functions.
  16. lex:add_rule('function', token(lexer.FUNCTION, word_match({
  17. 'APPEND', 'ATTRIB', 'CHKDSK', 'CHOICE', 'DEBUG', 'DEFRAG', 'DELTREE', 'DISKCOMP', 'DISKCOPY',
  18. 'DOSKEY', 'DRVSPACE', 'EMM386', 'EXPAND', 'FASTOPEN', 'FC', 'FDISK', 'FIND', 'FORMAT', 'GRAPHICS',
  19. 'KEYB', 'LABEL', 'LOADFIX', 'MEM', 'MODE', 'MORE', 'MOVE', 'MSCDEX', 'NLSFUNC', 'POWER', 'PRINT',
  20. 'RD', 'REPLACE', 'RESTORE', 'SETVER', 'SHARE', 'SORT', 'SUBST', 'SYS', 'TREE', 'UNDELETE',
  21. 'UNFORMAT', 'VSAFE', 'XCOPY'
  22. }, true)))
  23. -- Comments.
  24. local rem = (P('REM') + 'rem') * #lexer.space
  25. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(rem + '::')))
  26. -- Identifiers.
  27. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  28. -- Strings.
  29. lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
  30. -- Variables.
  31. local arg = '%' * lexer.digit + '%~' * lexer.alnum^1
  32. local variable = lexer.range('%', true, false)
  33. lex:add_rule('variable', token(lexer.VARIABLE, arg + variable))
  34. -- Labels.
  35. lex:add_rule('label', token(lexer.LABEL, ':' * lexer.word))
  36. -- Operators.
  37. lex:add_rule('operator', token(lexer.OPERATOR, S('+|&!<>=')))
  38. -- Fold points.
  39. lex:add_fold_point(lexer.KEYWORD, 'setlocal', 'endlocal')
  40. lexer.property['scintillua.comment'] = 'REM '
  41. return lex