Jump to content

Module:Sandbox/Lesser Cartographies/lua: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Bring this closer in line with the test I care about.
Closer...
Line 4: Line 4:


function p.test(frame)
function p.test(frame)
s="a, b and c, d and e, f and g, h"
s="aa, ba and ca, da and ea, fa and ga, ha"
for x,y in mw.ustring.gmatch(s, "and (%a), (%a)") do
for x,y in mw.ustring.gmatch(s, "and (%a-), (%a-)") do
mw.log(x,y)
mw.log(x,y)
end
end

Revision as of 15:43, 17 December 2014

-- Taking lua for a spin.
local p = {}
local l2u = require( "Module:LaTeX2UTF8" )

function p.test(frame)
	s="aa, ba and ca, da and ea, fa and ga, ha"
	for x,y in mw.ustring.gmatch(s, "and (%a-), (%a-)") do
		mw.log(x,y)
	end
end

function p.TranslateLaTeX(frame)
 	local s = [[
 	@book {MR0161818,
 	AUTHOR = {Erd{\H{o}}s, P{\'a}l and Sur{\'a}nyi, J{\'a}nos},
 	TITLE = {V\'alogatott fejezetek a sz\'amelm\'eletb{\H o}l},
 	PUBLISHER = {Tank\"onyvkiad\'o V\'allalat, Budapest},
 	YEAR = {1960},
 	PAGES = {250},
 	MRCLASS = {10.00},
 	MRNUMBER = {0161818 (28 \#5022)},
	} 
	]]
	s = l2u.translate_diacritics( s )
  	s = l2u.translate_special_characters( s )
  	local c = {}
  	c["citeparms"] = {}
  	c["nonciteparms"] = {}

  	local authorlist = mw.ustring.match( s, "AUTHOR = {(.-)}" )
  	--c["citeparms"]["author"] = authorlist
  	c["citeparms"]["last1"]  = mw.ustring.match( authorlist, "(%a-), %a- ")
  	c["citeparms"]["first1"] = mw.ustring.match( authorlist, "%a-, (%a-) ")

  	local authoridx=2
  	last,first = mw.ustring.match( authorlist, "and (%a-), (%a-)$") 
  	if(last) then
  		c["citeparms"]["last" .. authoridx] = last
  		c["citeparms"]["first" .. authoridx] = first --FIXME
  		authoridx = authoridx+1
  	end

  	c["nonciteparms"]["type"] 	= mw.ustring.match( s, "@(%a)+ {" )
  	c["citeparms"]["mr"] 		= mw.ustring.match( s, "{(MR%d+)," )
  	c["citeparms"]["title"]		= mw.ustring.match( s, "TITLE = {(.-)}" )
  	c["citeparms"]["publisher"]	= mw.ustring.match( s, "PUBLISHER = {(.-)}" )
  	c["citeparms"]["year"]		= mw.ustring.match( s, "YEAR = {(.-)}" )
  	c["citeparms"]["pages"]		= mw.ustring.match( s, "PAGES = {(.-)}" )
  	c["nonciteparms"]["mrclass"]= mw.ustring.match( s, "MRCLASS = {(.-)}" )
  	c["nonciteparms"]["mrnumber"] = mw.ustring.match( s, "MRNUMBER = {(.-)}" )
  
  	--return frame:expandTemplate{title = 'cite journal', args = c["citeparms"]}
  	return authorlist .. "|" .. c["citeparms"]["last2"] .. "," .. c["citeparms"]["first2"]	
end

return p