You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.
When we create parsers to implement new implementations we sometimes find that the regex we need to process a line is close to, but not exactly matching, a regex of a preexisting parser implementation.
For example, tag-change.ts handles parsing of the line [Power] GameState.DebugPrintPower() - TAG_CHANGE Entity=[entityName=Mecharoo id=54 zone=PLAY zonePos=1 cardId=BOT_445 player=2] tag=NUM_TURNS_IN_PLAY value=1
through the regex /^\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=\[entityName=(.*) id=(\d*) zone=.* zonePos=\d* cardId=(.*) player=(\d)\] tag=(.*) value=(\d*)/
but if we want to parse the line [Power] PowerTaskList.DebugPrintPower() - TAG_CHANGE Entity=manitu#1864 tag=TIMEOUT value=55
we would have to create a completely new regex like this \[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=(.*) tag=(.*) value=(\d*)
which we would also like to handle in tag-change.ts. However, our current implementation only supports one regex, and if we try to use the | operator, and use this regex: /^\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=(?:(?:\[entityName=(.*) id=(\d*) zone=.* zonePos=\d* cardId=(.*) player=(\d)\])|(.*)) tag=(.*) value=(\d*)/
we encounter a new problem when we have to represent this line in data as a typescript object Parts https://github.com/Tespa/hearthstone-parser/blob/46392bd07cd9cdaa52589adc0b020491da5bbf7f/src/line-parsers/tag-change.ts#L4. When we try to add new fields to the object and try to fill them, we have to leave some of them blank, which causes the typescript compiler to complain. We should try to design our interfaces such that this will not be an issue.
Alternatively, we could try to create a new parser for each of the individual regexes.
The text was updated successfully, but these errors were encountered:
I don't know if I completely understand the issue, but if you want to handle two (partially) different types in the Parts type, you can use union types.
I'm not sure if combining two regexes with | would resolve the issue you mentioned in the first line, which is why I don't know if I'm understanding this issue correctly.
actually this might be specific to how we handle it in tag-change and zone-change where we try to serialize the log line into a javascript object. Different regexes require different representations, which is why using a single interface Parts as in the code is incompatible with multiple regexes.
When we create parsers to implement new implementations we sometimes find that the regex we need to process a line is close to, but not exactly matching, a regex of a preexisting parser implementation.
For example, tag-change.ts handles parsing of the line
[Power] GameState.DebugPrintPower() - TAG_CHANGE Entity=[entityName=Mecharoo id=54 zone=PLAY zonePos=1 cardId=BOT_445 player=2] tag=NUM_TURNS_IN_PLAY value=1
through the regex
/^\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=\[entityName=(.*) id=(\d*) zone=.* zonePos=\d* cardId=(.*) player=(\d)\] tag=(.*) value=(\d*)/
but if we want to parse the line
[Power] PowerTaskList.DebugPrintPower() - TAG_CHANGE Entity=manitu#1864 tag=TIMEOUT value=55
we would have to create a completely new regex like this
\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=(.*) tag=(.*) value=(\d*)
which we would also like to handle in tag-change.ts. However, our current implementation only supports one regex, and if we try to use the | operator, and use this regex:
/^\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=(?:(?:\[entityName=(.*) id=(\d*) zone=.* zonePos=\d* cardId=(.*) player=(\d)\])|(.*)) tag=(.*) value=(\d*)/
we encounter a new problem when we have to represent this line in data as a typescript object Parts https://github.com/Tespa/hearthstone-parser/blob/46392bd07cd9cdaa52589adc0b020491da5bbf7f/src/line-parsers/tag-change.ts#L4. When we try to add new fields to the object and try to fill them, we have to leave some of them blank, which causes the typescript compiler to complain. We should try to design our interfaces such that this will not be an issue.
Alternatively, we could try to create a new parser for each of the individual regexes.
The text was updated successfully, but these errors were encountered: