lua-users home
lua-l archive

Fsyntax is ready (...but messing with syntax sucks! :)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I got the syntax-aware filtering done, and as a sample below is the code required to have "do ... end" be paranthesless function parameters.
So far, so good.
Selftests run, as long as a script don't have "for i=1,h do .." or similar while constructs. :)) Sad. Funny. The point is, there is now a slimmer (?) alternative for MetaLua, but messing with existing syntax is sure to have surprising concequences, all of which are not immediately obvious. Roberto et.al. have known this all the time, of course... Good for them.
http://kotisivu.dnainternet.fi/askok/bin/Filters-061206.zip
-rw-r--r-- 1 asko staff 550 Dec 6 00:22 Makefile
-rw-r--r-- 1 asko staff 5060 Dec 6 00:40 fdoend.lua
-rw-r--r-- 1 asko staff 12510 Dec 5 23:52 fluax.lua
-rw-r--r-- 1 asko staff 19283 Dec 6 00:23 fsyntax.lua
-rw-r--r-- 1 asko staff 13664 Dec 6 00:09 ftools.lua
-rw-r--r-- 1 asko staff 661 Dec 5 23:53 test-fdoend.lua
Please download it.
usage:	make
	make speed
requires:
	Lua 5.1 with token filter patch applied
If this was added with a tokenizer, and code generator, it could be any syntax engine. I have no interest to go further that road. But someone might? :)
-asko
-----
-- FDOEND.LUA
--
-- exp do .. end --> exp ( function() .. end )
--
-- usage: lua -lftools -lfsyntax -lfdoend ...
--
local alt= 	assert( FILTER.syntax.alt )
local altN_but_last= assert( FILTER.syntax.altN_but_last )
local opt= 	assert( FILTER.syntax.opt )
local args= 	assert( FILTER.syntax.args )
local block= 	assert( FILTER.syntax.block )
local exp= 	assert( FILTER.syntax.exp )
local explist1= assert( FILTER.syntax.explist1 )
local fieldlist= assert( FILTER.syntax.fieldlist )
local funcbody= assert( FILTER.syntax.funcbody )
local var= 	assert( FILTER.syntax.var )
local function CATCH( p, first )
 p:replace( first-1, 1, "(", "function", "(", ")" ) -- beginning
 p:replace( 0, 0, ")" ) -- after
end
local function CATCH2( p, first )
 p:replace( first-1, 0, "(" ) -- beginning
 p:replace( 0, 0, ")" ) -- after
end
FILTER.syntax.link{
 ["functioncall"]= { -- prefixexp
 alt{ ['(']= {exp,')'},
 ["<name>"]=true },
 altN_but_last{ ['[']= {exp,']'},
 ['.']= "<name>",
["do"]= { block, "end", convert=CATCH }, ["function"]= { funcbody, convert=CATCH2 },
 [':']= {"<name>",args},
 args },
 -- end of prefixexp
 opt{':',"<name>"},
 args
 },
 ["args"]= alt{ ['(']= { opt(explist1), ')' },
 ["<string>"]= true,
 ['{']= {opt(fieldlist),'}'},
 ["do"]= { block, "end", convert=CATCH },
 ["function"]= { funcbody, convert=CATCH2 },
 },
 }

AltStyle によって変換されたページ (->オリジナル) /