1 -- Copyright 2015-2016 David B. Lamkins <david@lamkins.net>. See LICENSE.
2 -- Faust LPeg lexer, see http://faust.grame.fr/
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'faust'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local line_comment
= '//' * l
.nonnewline^
0
15 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
16 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
19 local string = token(l
.STRING
, l
.delimited_range('"', true))
24 local exp = (P('e') * S('+-')^
-1 * int
)^
-1
25 local flt
= int
* (rad * int
)^
-1 * exp + int^
-1 * rad * int
* exp
26 local number = token(l
.NUMBER
, flt
+ int
)
29 local keyword
= token(l
.KEYWORD
, word_match
{
30 'declare', 'import', 'mdoctags', 'dependencies', 'distributed', 'inputs',
31 'outputs', 'par', 'seq', 'sum', 'prod', 'xor', 'with', 'environment',
32 'library', 'component', 'ffunction', 'fvariable', 'fconstant', 'int', 'float',
33 'case', 'waveform', 'h:', 'v:', 't:'
37 local identifier
= token(l
.IDENTIFIER
, l
.word
)
40 local punct
= S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\'')
41 local operator
= token(l
.OPERATOR
, punct
)
44 local mdoc
= P('<mdoc>') * (l
.any
- P('</mdoc>'))^
0 * P('</mdoc>')
45 local pragma
= token(l
.PREPROCESSOR
, mdoc
)
53 {'operator', operator
},
54 {'identifier', identifier
},