vis

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

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

smalltalk.lua

(1244B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Smalltalk 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('smalltalk')
      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 	'true false nil self super isNil not Smalltalk Transcript')))
     16 
     17 -- Types.
     18 lex:add_rule('type', token(lexer.TYPE, word_match(
     19 	'Date Time Boolean True False Character String Array Symbol Integer Object')))
     20 
     21 -- Identifiers.
     22 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     23 
     24 -- Strings.
     25 local sq_str = lexer.range("'")
     26 local word_str = '$' * lexer.word
     27 lex:add_rule('string', token(lexer.STRING, sq_str + word_str))
     28 
     29 -- Comments.
     30 lex:add_rule('comment', token(lexer.COMMENT, lexer.range('"', false, false)))
     31 
     32 -- Numbers.
     33 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
     34 
     35 -- Operators.
     36 lex:add_rule('operator', token(lexer.OPERATOR, S(':=_<>+-/*!()[]')))
     37 
     38 -- Labels.
     39 lex:add_rule('label', token(lexer.LABEL, '#' * lexer.word))
     40 
     41 -- Fold points.
     42 lex:add_fold_point(lexer.OPERATOR, '[', ']')
     43 
     44 lexer.property['scintillua.comment'] = '"|"'
     45 
     46 return lex