Skip to content

Instantly share code, notes, and snippets.

@Ragzouken
Created November 26, 2017 01:12
Show Gist options
  • Save Ragzouken/8826809d0003d114c155fafc2a2112ef to your computer and use it in GitHub Desktop.
Save Ragzouken/8826809d0003d114c155fafc2a2112ef to your computer and use it in GitHub Desktop.
start
= title:line "\n"+ sections:section*
{
return {
title: title,
sections: sections.filter(s => s != undefined),
};
}
line
= string:[^\n]+ { return string.join("") }
section
= "\n" {}
/ "#" line "\n" {}
/ "!" line "\n" {}
/ palette
/ room
/ tile
/ sprite
/ item
/ dialogue
/ variable
palette
= "PAL " id:line "\n"
"NAME " name:line "\n"
background:color "\n"
tile:color "\n"
sprite:color "\n"
{
return {
id: id,
name: name,
background: background,
tile: tile,
sprite: sprite,
}
}
color
= r:[0-9]+ "," g:[0-9]+ "," b:[0-9]+ {
return {
r: r.join(""),
g: g.join(""),
b: b.join(""),
}
}
coord
= x:number "," y:number { return [x, y]; }
room
= "ROOM " id:line "\n"
rows:row+
("NAME " name:line "\n")?
("WAL " walls:row)?
items:placedItem*
exits:exit*
"PAL " palette:id "\n"
{
return {
id: id,
tiles: rows,
name: name,
//walls: walls,
exits: exits,
palette: palette,
}
}
placedItem
= "ITM " id:id " " position:coord "\n"
{
return {
id: id,
position: position,
}
}
exit
= "EXT " src:coord " " room:id " " dst:coord "\n"
{
return {
src: src,
dst: dst,
room: room,
}
}
row
= line:id+ "\n"
{
return line;
}
tile
= "TIL " id:id "\n"
frame1:bitrow+
(">\n" frame2:bitrow+)?
("NAME " name:line)?
{
return {
id: id,
name: name,
frame1: frame1,
//frame2: frame2,
}
}
sprite
= "SPR " id:id "\n"
frame1:bitrow+
(">\n" frame2:bitrow+)?
("DLG " dialogue:id "\n")?
"POS " room:id " " pos:coord "\n"
{
return {
id: id,
position: [room, pos],
frame1: frame1,
//dialogue: dialogue,
}
}
item
= "ITM " id:id "\n"
frame1:bitrow+
(">\n" frame2:bitrow+)?
("NAME " name:line "\n")?
("DLG " dialogue:id "\n")?
{
return {
id: id,
name: name,
frame1: frame1,
//dialogue: dialogue,
}
}
dialogue
= "DLG " id:id "\n"
string:multistring
multistring
= '"""\n' scriptline* '"""\n'
/ string:line+ "\n"
{
return string.join("\n");
}
scriptline
= [^"][^\n]* "\n"
variable
= "VAR " id:id "\n"
value:number "\n"
{
return {
id: id,
value, value,
}
}
id
= chars:[^\n, ]+ ","? { return chars.join("").replace(",", ""); }
bitrow
= digits:[0|1]+ "\n" { return digits.map(d => parseInt(d)); }
number
= digits:[0-9]+ { return parseInt(digits.join("")); }
_ "whitespace"
= [ \t\n\r]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment