1 -- Copyright 2016 Alejandro Baez (https://keybase.io/baez). See LICENSE.
3 -- http://www.lexaloffle.com/pico-8.php
5 local l
= require('lexer')
6 local token
, word_match
= l
.token
, l
.word_match
7 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
9 local M
= {_NAME
= 'pico8'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
15 local line_comment
= '//' * l
.nonnewline_esc^
0
16 local comment
= token(l
.COMMENT
, line_comment
)
19 local number = token(l
.NUMBER
, l
.integer
)
22 local keyword
= token(l
.KEYWORD
, word_match
{
23 '__lua__', '__gfx__', '__gff__', '__map__', '__sfx__', '__music__'
27 local identifier
= token(l
.IDENTIFIER
, l
.word
)
30 local operator
= token(l
.OPERATOR
, S('_'))
35 {'identifier', identifier
},
38 {'operator', operator
},
41 -- Embed Lua into PICO-8.
42 local lua
= l
.load('lua')
44 local lua_start_rule
= token('pico8_tag', '__lua__')
45 local lua_end_rule
= token('pico8_tag', '__gfx__' )
46 l
.embed_lexer(M
, lua
, lua_start_rule
, lua_end_rule
)
49 pico8_tag
= l
.STYLE_EMBEDDED
52 M
._foldsymbols
= lua
._foldsymbols