vis

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

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

faust.lua

(1508B)


      1 -- Copyright 2015-2025 David B. Lamkins <david@lamkins.net>. See LICENSE.
      2 -- Faust LPeg lexer, see http://faust.grame.fr/
      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('faust')
      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 	'declare', 'import', 'mdoctags', 'dependencies', 'distributed', 'inputs', 'outputs', 'par', 'seq',
     16 	'sum', 'prod', 'xor', 'with', 'environment', 'library', 'component', 'ffunction', 'fvariable',
     17 	'fconstant', 'int', 'float', 'case', 'waveform', 'h:', 'v:', 't:'
     18 }))
     19 
     20 -- Identifiers.
     21 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     22 
     23 -- Strings.
     24 lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
     25 
     26 -- Comments.
     27 local line_comment = lexer.to_eol('//')
     28 local block_comment = lexer.range('/*', '*/')
     29 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
     30 
     31 -- Numbers.
     32 local int = lexer.digit^1
     33 local rad = P('.')
     34 local exp = (P('e') * S('+-')^-1 * int)^-1
     35 local flt = int * (rad * int)^-1 * exp + int^-1 * rad * int * exp
     36 lex:add_rule('number', token(lexer.NUMBER, flt + int))
     37 
     38 -- Pragmas.
     39 lex:add_rule('pragma', token(lexer.PREPROCESSOR, lexer.range('<mdoc>', '</mdoc>')))
     40 
     41 -- Operators.
     42 lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\'')))
     43 
     44 lexer.property['scintillua.comment'] = '//'
     45 
     46 return lex