Skip to content

Instantly share code, notes, and snippets.

@shitpoet
Created April 7, 2017 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shitpoet/313177a773db34349b371cb77fcb4b47 to your computer and use it in GitHub Desktop.
Save shitpoet/313177a773db34349b371cb77fcb4b47 to your computer and use it in GitHub Desktop.
basic HAML lexer for TextAdept
-- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
-- HAML LPeg lexer.
local l = require('lexer')
local token, word_match = l.token, l.word_match
local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
local M = {_NAME = 'haml'}
-- Whitespace.
local ws = token(l.WHITESPACE, l.space^1)
-- Comments.
local block_comment = '/' * (l.any - '%')^0
local comment = token(l.COMMENT, block_comment)
-- Strings.
local sq_str = l.delimited_range("'")
local dq_str = l.delimited_range('"')
local string = token(l.STRING, sq_str + dq_str)
-- Numbers.
local number = token(l.NUMBER, l.digit^1)
-- Keywords.
local keyword = token(l.KEYWORD, S('%') * l.alpha * (l.alnum + S('_-'))^0)
-- Identifiers.
local identifier = token(l.IDENTIFIER, l.alpha * (l.alnum + S('_-'))^0)
-- Operators.
local operator = token(l.OPERATOR, S('~!#*>+=|.,:;()[]{}'))
M._rules = {
{'whitespace', ws},
{'keyword', keyword},
{'identifier', identifier},
{'string', string},
{'comment', comment},
{'number', number},
{'operator', operator},
}
--M._FOLDBYINDENTATION = true
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment