1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Smalltalk LPeg lexer.
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
= 'smalltalk'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, l
.delimited_range('"', false, true))
17 local sq_str
= l
.delimited_range("'")
18 local literal
= '$' * l
.word
19 local string = token(l
.STRING
, sq_str
+ literal
)
22 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
25 local keyword
= token(l
.KEYWORD
, word_match
{
26 'true', 'false', 'nil', 'self', 'super', 'isNil', 'not', 'Smalltalk',
31 local type = token(l
.TYPE
, word_match
{
32 'Date', 'Time', 'Boolean', 'True', 'False', 'Character', 'String', 'Array',
33 'Symbol', 'Integer', 'Object'
37 local identifier
= token(l
.IDENTIFIER
, l
.word
)
40 local operator
= token(l
.OPERATOR
, S(':=_<>+-/*!()[]'))
43 local label
= token(l
.LABEL
, '#' * l
.word
)
49 {'identifier', identifier
},
54 {'operator', operator
},
58 _patterns
= {'[%[%]]'},
59 [l
.OPERATOR
] = {['['] = 1, [']'] = -1}