[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Problems with list parsing

Problems with list parsing

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Thu 06 Aug 2009 12:15 AM (UTC)

Amended on Thu 06 Aug 2009 12:25 AM (UTC) by Nick Gammon

Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 06 Aug 2009 12:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #2 on Thu 06 Aug 2009 12:45 AM (UTC)
Message
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...
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 06 Aug 2009 01:00 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #4 on Thu 06 Aug 2009 01:43 AM (UTC)
Message
Wiped my list completely and started over, and it worked properly. Thanks! You always have a great answer.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,112 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]