简体   繁体   中英

Parsing a text with “xxx = { .. }” in C# with Sprache

As you may already guess, I need some help. I'm currently working on a WPF with a friend, but we have a problem: We need to parse a certain type of text but we have just no idea how to do it. We found Sprache and it seems like a great parser, but we don't know how to use it. Also: English isn't our native language so the introduction article isn't very easy to understand for us.

So we made the decision to ask about it here on Stackoverflow.

The text we want to parse is located in a simple .txt file and looks like this:

focus_tree = {
id = german_focus

country = {
    factor = 0

    modifier = {
        add = 10
        tag = GER
    }
}

default = no

focus = {
    id = GER_autobahn
    icon = GFX_goal_generic_construct_infrastructure
    x = 0
    y = 0
    cost = 10
    ai_will_do = {
        factor = 12
    }

    completion_reward = {
        custom_effect_tooltip = GER_autobahn_tt
        hidden_effect = {
            64 = {
                if = {
                    limit = { is_controlled_by = ROOT }
                    add_building_construction = {
                        type = infrastructure
                        level = 10
                        instant_build = yes
                    }
                }
            }
            59 = {
                if = {
                    limit = { is_controlled_by = ROOT }

                    add_building_construction = {
                        type = infrastructure
                        level = 10
                        instant_build = yes
                    }
                }
            }
            60 = {
                if = {
                    limit = { is_controlled_by = ROOT }
                    add_building_construction = {
                        type = infrastructure
                        level = 10
                        instant_build = yes
                    }
                }
            }
            54 = {
                if = {
                    limit = { is_controlled_by = ROOT }
                    add_building_construction = {
                        type = infrastructure
                        level = 10
                        instant_build = yes
                    }
                }
            }
        }       
    }
}

(It's from a game called "Hearts of Iron IV" and only a small part of the whole thing)

Could you guys give us a little help or a small hint to start up?

Thanks in advance, Stuffi

That looks a lot like JSON, but with unquoted tokens instead of strings, equals signs (=) instead of colons (:), and no commas between properties. Why don't you check out the library SpracheJSON and see if you can modify it slightly to parse your file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM