Content deleted Content added
Guarapiranga (talk | contribs) |
|||
Line 462:
:::::I fixed [[Module:Graph table]] but now [[User:Guarapiranga/sandbox/5]] has another error. Regardless of this module, I have not seen any support either here or where it was raised at [[WP:VPT]] for the idea of having a module parse the wikitext of a page to extract data from a wikitable. I wouldn't put much effort into that approach. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:34, 25 May 2021 (UTC)
::::::Thanks, {{u|Johnuniq}}. I fixed the regex, as you recommended, and it's pulling the data, but it seems this module needs each data point on a different line(?):{{pre|addSlice( i, mw.ustring.match( slice, '^%(%s*(.-)%s*%)$' ) )}} But what's the deal with ^ and $, if [[mw:Extension:Scribunto/Lua reference manual#string.gmatch|Scribunto manual]] says that {{tq|a '^' at the start of a pattern is not magic, as this would prevent the iteration}}, and that {{tq|it is treated as a literal character}}? Is that why it uses mw.ustring instead? The [[mw:Extension:Scribunto/Lua reference manual#Ustring patterns|ustring patterns section]] doesn't say anything about mw.ustring extending the controls to ^ and $. [[User:Guarapiranga|— 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚]] ([[User talk:Guarapiranga|talk]]) 16:16, 25 May 2021 (UTC)
:::::::Before the <code>addSlice(...)</code> code you posted above is <code>for slice in...</code>. The <code>for</code> loop gets each "<code>(...)</code>" substring (any text in balanced parentheses) and passes it to <code>addSlice</code>. The <code>^</code> and <code>$</code> you mention are redundant as <code>slice</code> will start and end with parentheses. However, they work because it's <code>match</code>, not <code>gmatch</code>. The code uses mw.ustring but it does not need to with the regex that it uses. Following that requires a bit of experience with [[UTF-8]] but, in brief, it's only when you have a regex like <code>[x◆]*</code>, and probably some others, (with a Unicode character) that mw.ustring is needed. Scribunto implements mw.ustring by using Lua to replace the regex library which is a breathtaking accomplishment but which makes it slower than using plain strings. When I've got some time in a few hours I'll look at what's happening, bearing in mind that I still do not think parsing wikitext in Lua is sustainable. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 22:44, 25 May 2021 (UTC)
|