[code] [textadept] How to use lexer.starts_line?

From: Joshua Krämer <joshua.kraemer.att.gmail.com>
Date: Mon, 18 Aug 2014 22:50:44 +0200

Hi all,

I am trying to create a lexer and cannot figure out how to use the
lexer.starts_line function. Let us say that I want to match one of the
characters a, b or c at the beginning of a line or after some whitespace
characters at the beginning of a line. Attached is a minimal example
that does not work. I have also tried several variants with #-prefixed
patterns without success. It would be great if somebody could give me
a hint.

Thanks and kind regards,
Joshua

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

local M = {_NAME = 'test_lexer'}

local ws = token(l.WHITESPACE, l.space^1)
local keyword = l.starts_line(S(' \t')^0 * token(l.KEYWORD, S('abc')))

M._rules = {
  {'keyword', keyword},
  {'whitespace', ws},
}

return M

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 18 Aug 2014 - 16:50:44 EDT

This archive was generated by hypermail 2.2.0 : Tue 19 Aug 2014 - 06:49:21 EDT