Re: [code] Factor lexer for Textadept

From: John Benediktsson <mrjbq7.att.gmail.com>
Date: Wed, 3 Apr 2013 07:43:43 -0700

>
> 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.
>>
>
Some other ideas:

Can you make a stateful parser, processing tokens and when "(" is seen, go
into "stack effect" mode, looking for ")" and consider if it is a valid
stack effect?

Or maybe a regexp parser, looking for something
like "\(\s+(\S*\s+)*\-\-(\s+\S*)*\s+\)". Highlighting nested stack effects
might require a bit more work, though.

If it is helpful, you can see a FactorLexer[1] in Pygments that is used to
highlight source code on Github.

Or take a look at our VIM syntax file[2], which is fairly complete.

Best,
John.

---
[1]
https://bitbucket.org/birkenfeld/pygments-main/src/76d061ee02f649abfb95f3505cbbb8a6c2d52f2f/pygments/lexers/agile.py?at=default#cl-1461
[2]
https://github.com/slavapestov/factor/blob/master/misc/vim/syntax/factor.vim#L153
-- 
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:43:43 EDT

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