ui: add support for blink style attribute
[vis.git] / lexers / pico8.lua
blob5e95948fdf9af2cea6af196396441a1efca5ecba
1 -- Copyright 2016 Alejandro Baez (https://keybase.io/baez). See LICENSE.
2 -- PICO-8 Lexer.
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'}
11 -- Whitespace
12 local ws = token(l.WHITESPACE, l.space^1)
14 -- Comments
15 local line_comment = '//' * l.nonnewline_esc^0
16 local comment = token(l.COMMENT, line_comment)
18 -- Numbers
19 local number = token(l.NUMBER, l.integer)
21 -- Keywords
22 local keyword = token(l.KEYWORD, word_match{
23 '__lua__', '__gfx__', '__gff__', '__map__', '__sfx__', '__music__'
26 -- Identifiers
27 local identifier = token(l.IDENTIFIER, l.word)
29 -- Operators
30 local operator = token(l.OPERATOR, S('_'))
32 M._rules = {
33 {'whitespace', ws},
34 {'keyword', keyword},
35 {'identifier', identifier},
36 {'comment', comment},
37 {'number', number},
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)
48 M._tokenstyles = {
49 pico8_tag = l.STYLE_EMBEDDED
52 M._foldsymbols = lua._foldsymbols
54 return M