vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

fsharp.lua

(2369B)


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