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

fish.lua (2164B)


  1. -- Copyright 2015-2024 Jason Schindler. See LICENSE.
  2. -- Fish (http://fishshell.com/) script 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('fish')
  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. 'alias', 'and', 'begin', 'bg', 'bind', 'block', 'break', 'breakpoint', 'builtin', 'case', 'cd',
  12. 'command', 'commandline', 'complete', 'contains', 'continue', 'count', 'dirh', 'dirs', 'echo',
  13. 'else', 'emit', 'end', 'eval', 'exec', 'exit', 'fg', 'fish', 'fish_config', 'fishd',
  14. 'fish_indent', 'fish_pager', 'fish_prompt', 'fish_right_prompt', 'fish_update_completions', 'for',
  15. 'funced', 'funcsave', 'function', 'functions', 'help', 'history', 'if', 'in', 'isatty', 'jobs',
  16. 'math', 'mimedb', 'nextd', 'not', 'open', 'or', 'popd', 'prevd', 'psub', 'pushd', 'pwd', 'random',
  17. 'read', 'return', 'set', 'set_color', 'source', 'status', 'switch', 'test', 'trap', 'type',
  18. 'ulimit', 'umask', 'vared', 'while'
  19. }))
  20. -- Identifiers.
  21. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  22. -- Variables.
  23. lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.word + lexer.range('{', '}', true))))
  24. -- Strings.
  25. local sq_str = lexer.range("'", false, false)
  26. local dq_str = lexer.range('"')
  27. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  28. -- Shebang.
  29. lex:add_rule('shebang', token(lexer.COMMENT, lexer.to_eol('#!/')))
  30. -- Comments.
  31. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  32. -- Numbers.
  33. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  34. -- Operators.
  35. lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*^&|~.,:;?()[]{}')))
  36. -- Fold points.
  37. lex:add_fold_point(lexer.KEYWORD, 'begin', 'end')
  38. lex:add_fold_point(lexer.KEYWORD, 'for', 'end')
  39. lex:add_fold_point(lexer.KEYWORD, 'function', 'end')
  40. lex:add_fold_point(lexer.KEYWORD, 'if', 'end')
  41. lex:add_fold_point(lexer.KEYWORD, 'switch', 'end')
  42. lex:add_fold_point(lexer.KEYWORD, 'while', 'end')
  43. lexer.property['scintillua.comment'] = '#'
  44. return lex