vis

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

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

dart.lua

(1894B)


      1 -- Copyright 2013-2025 Mitchell. See LICENSE.
      2 -- Dart LPeg lexer.
      3 -- Written by Brian Schott (@Hackerpilot on Github).
      4 
      5 local lexer = require('lexer')
      6 local token, word_match = lexer.token, lexer.word_match
      7 local P, S = lpeg.P, lpeg.S
      8 
      9 local lex = lexer.new('dart')
     10 
     11 -- Whitespace.
     12 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
     13 
     14 -- Keywords.
     15 lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
     16 	'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do', 'else', 'enum',
     17 	'extends', 'false', 'final', 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow',
     18 	'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void', 'while', 'with'
     19 }))
     20 
     21 -- Built-ins.
     22 lex:add_rule('builtin', token(lexer.CONSTANT, word_match{
     23 	'abstract', 'as', 'dynamic', 'export', 'external', 'factory', 'get', 'implements', 'import',
     24 	'library', 'operator', 'part', 'set', 'static', 'typedef'
     25 }))
     26 
     27 -- Strings.
     28 local sq_str = S('r')^-1 * lexer.range("'", true)
     29 local dq_str = S('r')^-1 * lexer.range('"', true)
     30 local tq_str = S('r')^-1 * (lexer.range("'''") + lexer.range('"""'))
     31 lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str))
     32 
     33 -- Identifiers.
     34 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     35 
     36 -- Comments.
     37 local line_comment = lexer.to_eol('//', true)
     38 local block_comment = lexer.range('/*', '*/', false, false, true)
     39 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
     40 
     41 -- Numbers.
     42 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
     43 
     44 -- Operators.
     45 lex:add_rule('operator', token(lexer.OPERATOR, S('#?=!<>+-*$/%&|^~.,;()[]{}')))
     46 
     47 -- Annotations.
     48 lex:add_rule('annotation', token(lexer.ANNOTATION, '@' * lexer.word^1))
     49 
     50 -- Fold points.
     51 lex:add_fold_point(lexer.OPERATOR, '{', '}')
     52 lex:add_fold_point(lexer.COMMENT, '/*', '*/')
     53 
     54 lexer.property['scintillua.comment'] = '//'
     55 
     56 return lex