Problems with list parsing

Posted by Tiopon on Thu 06 Aug 2009 12:15 AM — 5 posts, 18,359 views.

USA #0
I'm using the following trigger to parse my inventory...
<triggers>
  <trigger
   keep_evaluating="y"
   match="^([a-z#_\' -:]*) ([a-zA-Z\ .]*)$"
   name="skill_line"
   regexp="y"
   send_to="12"
   sequence="50"
  >
  <send>local SkillName = string.gsub("%1", ":%s+$", "")
local SubName = string.gsub(SkillName, "[ '#-]", "_")
local SkillLevel = string.gsub("%2", "[.]", "")

skill_table[SubName] = skill_table[SubName] or {}
skill_table[SubName].name = SkillName
skill_table[SubName].level = SkillLevel
skill_table[SubName].count = GetVariable (SubName .. "_skill")
</send>
  </trigger>
</triggers>

The list looks like one of the following...


delior's_pocket_dimension: Proficient.
language#southern:         Not Very Good.
stone working:             Poor.


Specifically, the issue is with the delior's_pocket_dimension skill... this one, because it only has a single space, fails to remove the :, unlike the others... the normal ones parse like this...
Quote:
delior's_pocket_dimension: nil Proficient
language#southern 68 Not Very Good
stone working 30 Poor

As you can see, delior's_pocket_dimension fails, including having a : remaining in its name.

Basically, I'm trying to see if there's a better way to have it parse the names, removing all ending spaces in the skill names. The main issue is that spaces may be found in the skill names, as well as their descriptive names, and I haven't found a better way to get results. This works perfectly except for with this one skill.
Amended on Thu 06 Aug 2009 12:25 AM by Nick Gammon
Australia Forum Administrator #1
Your regular expression in the trigger looks for a space between wildcard 1 and wildcard 2, so the space after the colon is not returned as part of wildcard 1.

A simple fix would be to change the Lua regexp to:


local SkillName = string.gsub("%1", ":%s*$", "")


Now that looks for zero or more spaces, rather than 1 or more spaces.
USA #2
Okay, so set it to this, which is what I believe you suggested...
<triggers>
  <trigger
   keep_evaluating="y"
   match="^([a-z#_\' -:]*) ([a-zA-Z\ .]*)$"
   name="skill_line"
   regexp="y"
   send_to="12"
   sequence="50"
  >
  <send>local SkillName = string.gsub("%1", ":%s*$", "")
local SubName = string.gsub(SkillName, "[ '#-]", "_")
local SkillLevel = string.gsub("%2", "[.]", "")

skill_table[SubName] = skill_table[SubName] or {}
skill_table[SubName].name = SkillName
skill_table[SubName].level = SkillLevel
skill_table[SubName].count = GetVariable (SubName .. "_skill")
</send>
  </trigger>
</triggers>


Still parses the same though...
Australia Forum Administrator #3
I pasted in your trigger, enabled it, and tested it like this:


delior's_pocket_dimension: Proficient.
language#southern:         Not Very Good.
stone working:             Poor.

require "tprint"; tprint (skill_table)

"delior_s_pocket_dimension":
  "level"="Proficient"
  "name"="delior's_pocket_dimension"
"language_southern":
  "level"="Not Very Good"
  "name"="language#southern"
"stone_working":
  "level"="Poor"
  "name"="stone working"


It seems to have worked. The final colon is added by tprint. The name inside the quotes has the colon removed.
USA #4
Wiped my list completely and started over, and it worked properly. Thanks! You always have a great answer.