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

fsharp.lua (2383B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- F# 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('fsharp', {fold_by_indentation = 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. 'abstract', 'and', 'as', 'assert', 'asr', 'begin', 'class', 'default', 'delegate', 'do', 'done',
  12. 'downcast', 'downto', 'else', 'end', 'enum', 'exception', 'false', 'finaly', 'for', 'fun',
  13. 'function', 'if', 'in', 'iherit', 'interface', 'land', 'lazy', 'let', 'lor', 'lsl', 'lsr', 'lxor',
  14. 'match', 'member', 'mod', 'module', 'mutable', 'namespace', 'new', 'null', 'of', 'open', 'or',
  15. 'override', 'sig', 'static', 'struct', 'then', 'to', 'true', 'try', 'type', 'val', 'when',
  16. 'inline', 'upcast', 'while', 'with', 'async', 'atomic', 'break', 'checked', 'component', 'const',
  17. 'constructor', 'continue', 'eager', 'event', 'external', 'fixed', 'functor', 'include', 'method',
  18. 'mixin', 'process', 'property', 'protected', 'public', 'pure', 'readonly', 'return', 'sealed',
  19. 'switch', 'virtual', 'void', 'volatile', 'where',
  20. -- Booleans.
  21. 'true', 'false'
  22. }))
  23. -- Types.
  24. lex:add_rule('type', token(lexer.TYPE, word_match{
  25. 'bool', 'byte', 'sbyte', 'int16', 'uint16', 'int', 'uint32', 'int64', 'uint64', 'nativeint',
  26. 'unativeint', 'char', 'string', 'decimal', 'unit', 'void', 'float32', 'single', 'float', 'double'
  27. }))
  28. -- Identifiers.
  29. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  30. -- Strings.
  31. local sq_str = lexer.range("'", true)
  32. local dq_str = lexer.range('"', true)
  33. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  34. -- Comments.
  35. local line_comment = lexer.to_eol('//')
  36. local block_comment = lexer.range('(*', '*)', false, false, true)
  37. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  38. -- Numbers.
  39. lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer * S('uUlL')^-1))
  40. -- Preprocessor.
  41. lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * S('\t ')^0 *
  42. word_match('else endif endregion if ifdef ifndef light region')))
  43. -- Operators.
  44. lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/^.,:;~!@#%^&|?[](){}')))
  45. lexer.property['scintillua.comment'] = '//'
  46. return lex