|
| 08 Aug 2017 02:25 PM |
[PLEASE NOTE] in the parsing expressions I will be using the following letters to represent symbols like the percent and multiplication due to roblox's filter: p = % m = *
I have a scenario in which I need to be able to match an optional static sub of text####a##tring, but that static portion could be 1 of 2 possibilities.
Here are some examples of possibilities that I need to be able to parse: "foo + offset bar"
"*foo + bar"
"foo + bar"
"*foo + *bar"
"offset foo + offset bar"
where either "offset" or "*" should be optional in front of each identifier. (in this case "foo" and "bar")
Is there any actual way to do this using Lua's string matching? I was thinking of something like:
"[offset]?psmpm?psm[_pa][_pw]m" but "[offset]?" is only an optional character class that can either be o, f, s, e, or t; and even if it wasn't users would be able to send input like:
"offset * foo + offset * bar"
without getting a proper warning.
From a logical standpoint what I am trying to do would probably look something like
("offset" | "*" | "") & "psm[_pa][_pw]m" |
|
|
| Report Abuse |
|
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 08 Aug 2017 03:20 PM |
I don't understand what you are trying to do.
Can you describe what you need to parse and what it should be parsed into? |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2017 03:41 PM |
@chimmihc what I am trying to parse the given string into is kind of irrelevant since my question regards how to actually match a given optional format of static text within a given string using Lua's parse expressions.
If you need more info on the situation then here are some detailed examples; if a user sent in a string like such:
"foo + bar"
then the values foo and bar would be added, but if a user sent in a string like such:
"offset foo + bar"
then the virtual address of foo, and the value bar would be added. Like-wise if a user sent in a string like such:
"foo + * bar"
then the value foo and the value at the virtual address at bar would be added.
The problem is that an identifier like "foo", or "bar" can only be preceded by "offset" or "*" but both "offset" and "*" must be optional.
the logical example I gave kind of explains a pseudo code of what I am trying to do: ("offset" or "*" or "") and "psm[_pa][_pw]m"
(change all 'p's to %, and all 'm's to * in the Lua parse expression) |
|
|
| Report Abuse |
|
|
| |
|
Mescalyne
|
  |
| Joined: 20 Apr 2017 |
| Total Posts: 418 |
|
|
| 08 Aug 2017 04:01 PM |
Oh god, are you still trying to change Lua to a freaking C-like language? This is getting ridiculous. I find it easier to create a tokenizer that processes a string like an input stream, character-by-character and determining token type along with that, too. You can then (relatively) easily parse the tokens into expressions. |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2017 04:40 PM |
| ########## yeah, I still am lol. Anyway thanks for the idea; I will try that out. |
|
|
| Report Abuse |
|
|