Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Current Parser does not Allow for Multiple Regexs #22

@rikumiyao

Description

@rikumiyao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions