Re: [code] Factor lexer for Textadept

From: Mitchell <m.att.foicica.com>
Date: Wed, 3 Apr 2013 10:32:14 -0400 (Eastern Daylight Time)

Hi Michael,

On Wed, 3 Apr 2013, Michael Richter wrote:

> Yeah, that's the problem I've got with the way things are now.
>
> A stack declaration is ( words words words -- words words words ). It
> may be nested as well. So you could have ( words words ( words -- words
> ) -- words words ). All of the words are optional, incidentally. The
> only fixed parts are (, ) and --. Those *must* be there.
>
> Like Forth, Factor is, indeed, whitespace delimited so ( must have
> whitespace before and after it as must ) and --. This is what I tried
> in earlier attempts to leverage, but failed with. I just don't know
> LPEG well enough yet to figure out even where to begin with this.

Try a function match (untested):

#P('( ') * lpeg.P(function(input, index)
   local paren_count = 1
   for i = index + 2, #input do
     local char = input:sub(i, i)
     if char == '(' then
       paren_count = parent_count + 1
     elseif char == ')' then
       parent_count = parent_count - 1
       if parent_count == 0 then return nil end -- '--' not found
     elseif char == '-' and input:sub(i + 1, i + 1) == '--' then
       return index
     end
   end
   return nil
end) * l.delimited_range('(', ')')

Performance could be an issue though...

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 Wed 03 Apr 2013 - 10:32:14 EDT

This archive was generated by hypermail 2.2.0 : Thu 04 Apr 2013 - 06:36:20 EDT