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

faust.lua (1511B)


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