aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexlua/props.lua
blob: 240ace78fc1827ed6b260bed0769db111a252f91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt.
-- Props LPeg lexer.

local lexer = require('lexer')
local token, word_match = lexer.token, lexer.word_match
local P, S = lpeg.P, lpeg.S

local lex = lexer.new('props', {lex_by_line = true})

-- Whitespace.
lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))

-- Colors.
lex:add_rule('color', token('color', '#' * lexer.xdigit * lexer.xdigit *
  lexer.xdigit * lexer.xdigit * lexer.xdigit * lexer.xdigit))
lex:add_style('color', lexer.styles.number)

-- Comments.
lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))

-- Equals.
lex:add_rule('equals', token(lexer.OPERATOR, '='))

-- Strings.
local sq_str = lexer.range("'")
local dq_str = lexer.range('"')
lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))

-- Variables.
lex:add_rule('variable', token(lexer.VARIABLE, '$' *
  lexer.range('(', ')', true)))

return lex