Re: [textadept] Re: Lexer

From: mitchell <c....at.caladbolg.net>
Date: Wed, 15 Jun 2011 08:58:21 -0400 (Eastern Daylight Time)

Hi Anton,

On Wed, 15 Jun 2011, anton wrote:

> The main problem is that if I do something wrong in a module, TA
> (well, Lua) gives a meaningful
> error message. If I do something wrong in a lexer TA simply crashes.

Error messages will be printed to STDOUT or STDERR in Linux.

> First try: only to lex "\command[word" or even simply "[word"
> (this doesn't work)
>
> -- already defined
> local operator = token(l.OPERATOR, S('$&%#{}'))
>
> local preprocessor = #operator* P('[')* token(l.PREPROCESSOR, l.word)
>
> -- local preprocessor = #P('[') * token(l.PREPROCESSOR, l.word)

The '#' operator matches without consuming anything so you need to have
another operator token immediately after.

local preprocessor = #P('[') * operator * token(l.PREPROCESSOR, l.word)

> _rules = {
> { 'whitespace', ws },
> { 'comment', comment },
> { 'string', string },
> { 'keyword', command },
> { 'operator', operator },
> { 'preprocessor', preprocessor },
> { 'any_char', l.any_char },
> }
>

'preprocessor' needs to come before 'operator' or 'operator' will always
match first.

> The thing I most confused about is the mixture of strings and LPeg
> patterns
> like S('letters'), P('string') like this
> local block_comment = '\\begin{comment}' * (l.any - '\
> \end{comment}')^0 *
> P('\\end{comment}')^-1

If an LPeg pattern is part of a binary operator, like '-', then the other
operand is converted to a pattern (lpeg.P) if it isn't one already.

mitchell
Received on Wed 15 Jun 2011 - 08:58:21 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 12:10:51 EST