1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
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
= 'io_lang'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local line_comment
= (P('#') + '//') * l
.nonnewline^
0
15 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
16 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
19 local sq_str
= l
.delimited_range("'")
20 local dq_str
= l
.delimited_range('"')
21 local tq_str
= '"""' * (l
.any
- '"""')^
0 * P('"""')^
-1
22 local string = token(l
.STRING
, tq_str
+ sq_str
+ dq_str
)
25 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
28 local keyword
= token(l
.KEYWORD
, word_match
{
29 'block', 'method', 'while', 'foreach', 'if', 'else', 'do', 'super', 'self',
30 'clone', 'proto', 'setSlot', 'hasSlot', 'type', 'write', 'print', 'forward'
34 local type = token(l
.TYPE
, word_match
{
35 'Block', 'Buffer', 'CFunction', 'Date', 'Duration', 'File', 'Future', 'List',
36 'LinkedList', 'Map', 'Nop', 'Message', 'Nil', 'Number', 'Object', 'String',
41 local identifier
= token(l
.IDENTIFIER
, l
.word
)
44 local operator
= token(l
.OPERATOR
, S('`~@$%^&*-+/=\\<>?.,:;()[]{}'))
50 {'identifier', identifier
},
54 {'operator', operator
},
58 _patterns
= {'[%(%)]', '/%*', '%*/', '#', '//'},
59 [l
.OPERATOR
] = {['('] = 1, [')'] = -1},
61 ['/*'] = 1, ['*/'] = -1, ['#'] = l
.fold_line_comments('#'),
62 ['//'] = l
.fold_line_comments('//')