I want to read data in a format like the following using Java.
[scenario]
id=my_first_scenario
next_scenario=null
name=_"My First Scenario."
map_data="{~add-ons/my_first_campaign/maps/my_first_map.map}"
turns=30
[side]
side=1
controller=human
team_name="good"
user_team_name= _ "My Team"
id=MyLeader
name= _ "My Leader's Name"
type="Elvish Ranger"
unrenameable=yes
canrecruit=yes
recruit="Elvish Fighter, Elvish Archer, Elvish Shaman"
gold=100
[/side]
[side]
side=2
controller=ai
team_name="bad"
user_team_name= _ "Bad Guys"
id="EnemyLeader"
name= _ "My Villain"
type= "Orcish Warrior"
unrenameable=yes
canrecruit=yes
recruit="Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider"
gold=100
[/side]
[/scenario]
I want to develop an API that would read such content in a generic manner, for example, having methods like getChildren
, getAttributes
. I'm wondering if there are libraries that support this kind of task.
Following are what I have come up with,
Since this is a simple language of it's own (like XML), should I use a library like antlr? Or is that too complex for this task?
Should I use regex for parsing this data?
Should I process the text manually as a stream, and identify the tags/attributes as they arrive?
Or is there a better/different way than all above?
For anyone who is interested this markup language is used in a game called Battle for Wesnoth, which is in c++. I want to parse this data using Java.