Re: [code] Factor lexer for Textadept

From: Mitchell <m.att.foicica.com>
Date: Mon, 8 Apr 2013 11:30:26 -0400 (Eastern Daylight Time)

Hi Michael,

On Thu, 4 Apr 2013, Michael Richter wrote:

> Here's an almost-functioning version for nested lexing:
>
> local ws = l.space
> local maybe_some = function(p) return p^0 end
> local all_but = function(p) return P(1) - p end
> local with_ws = function(p) return p * #ws end
> local ws_with = function(p) return B(ws) * p end
> local ws_with_ws = function(p) return B(ws) * p * #ws end
> local text_to = function(t) return maybe_some(all_but(t)) end
> local stack_declaration = with_ws(P{
> 'stack';
> stack = with_ws(P'(') * lpeg.V'open_words'
> * ws_with_ws(P'--') * lpeg.V'close_words'
> * ws_with(P')'),
>
> open_words = ( some(ws)
> * lpeg.V'colon_word'
> * lpeg.V'open_words' )
> + text_to(P'--'),
> close_words = lpeg.V'colon_word'
> + text_to(P')'),
> colon_word = text_to(P':') * some(ws) *
> lpeg.V'stack',
> })
>
> This will correctly match things like:
>
> ( word word -- word word )
> ( -- word )
> ( word -- )
> ( -- )
> ( word -- word: ( word -- word ) )
> ( word word: ( word -- word ) -- )
>
> It fails, however, on things like:
>
> ( word: ( word -- word ) *failed_word* -- *failed_word* )
> ( word: ( word -- word ) -- *failed_word* )
> ( word -- word: ( word -- word ) *failed_word* )

I put 'stack_declaration' and 'constructor_words' in two separately styled
tokens since they both match parentheses. For the failing patterns, The
last parenthesis is styled as a 'constructor_words', so it seems that a
trailing ')' in your 'stack_declaration' pattern is not being matched
properly. I'm not exactly sure where though. Grammars with nesting hurts
my brain. I would recommend creating separately styled tokens for each
part of your grammar and not wrap the grammar in a token by itself. This
way you can see the different matches and perhaps that will help you
determine what is going wrong.

Cheers,
Mitchell

-- 
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 08 Apr 2013 - 11:30:26 EDT

This archive was generated by hypermail 2.2.0 : Tue 09 Apr 2013 - 06:49:33 EDT