Magic Grammar
Posted: 04 Sep 2011, 13:41
I've decided to start up a project to create a grammar for magic card rules. This has been discussed here before but as far as I know it have never really taken off.
Some arbitrary requirements I set forth for this are;
Language / tool independent.
Meaning it should not be tied to a particular programming language or require a certain tool.
Understandable for a computer.
Just getting a grammar could probably be done mechanically rather quickly but it would not be very useful. In order for it to be useful rules in the grammar have to be arranged so that you can figure out what parts do what.
This is probably what most would strive for but I think it's worth mentioning anyways.
The "Overrule" tool:
I implemented a tool to help me develop the grammar. It has two purposes; see that I don't break anything when moving forward and debugging the current work. It performs those duties ok (even though it takes 10+ minutes for a complete run-through of everything).
It also presents the output from passing a rule through the grammar. There's a "quickstart" version linked below if anyone wants to try it out. Check out the "about" tab for a minimal manual in that case.
The grammar:
The grammar is ISO EBNF with a few exceptions. Exceptions (A matches B but not C) and comments are not supported. This also means that 1+ repetition is not supported. I have while prototyping not found any need for exceptions so I've not implemented support for it. Comments will probably be implemented as the grammar grows and need for documentation and explantion arises. This is of course a limitation in the validation tool and not a problem with the grammar.
Special forms are used to move "variables" out of the grammar. Enumerated items that are expected to change (or if there's just a whole bunch of them) reside in .special-files. This goes for things such as all the various types. This is to make it easier to inject new items without having to change the actual grammar. Will probably refactor keywords to use that format in the future as well.
Current status:
The overrule tool is "complete". Meaning I'm currently satified with how it works. There are improvements to be made but nothing that needs immediate attention.
The grammar itself is just getting started. It currently handles most keywords and some other arbitrarily chosen rules. Basically the easy stuff.
I've also been looking for other magic grammars. The only one I actually know about though is https://bitbucket.org/eswald/incantus/s ... 3/parsing/ . If anyone has something laying around I'd be interested in seeing it.
Other than that any help is welcome. It might be a bit early to ask for extra hands since there's not much to work on yet but advice and general comments are welcome too.
Links:
Overrule - application only
http://dl.dropbox.com/u/2771470/overrul ... dalone.jar
Overrule - "quickstart"
http://dl.dropbox.com/u/2771470/overrule/overrule.zip
cards.xml
viewtopic.php?f=27&t=1347
core.ebnf
https://github.com/karmag/loa-grammar
Overrule code
https://github.com/karmag/overrule
https://github.com/karmag/bana (dependency)
https://github.com/karmag/loa-util (dependency)
ISO EBNF (actually the final draft version)
http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf
EBNF on wikipedia
http://en.wikipedia.org/wiki/Extended_B ... 3Naur_Form
Some arbitrary requirements I set forth for this are;
Language / tool independent.
Meaning it should not be tied to a particular programming language or require a certain tool.
Understandable for a computer.
Just getting a grammar could probably be done mechanically rather quickly but it would not be very useful. In order for it to be useful rules in the grammar have to be arranged so that you can figure out what parts do what.
This is probably what most would strive for but I think it's worth mentioning anyways.
The "Overrule" tool:
I implemented a tool to help me develop the grammar. It has two purposes; see that I don't break anything when moving forward and debugging the current work. It performs those duties ok (even though it takes 10+ minutes for a complete run-through of everything).
It also presents the output from passing a rule through the grammar. There's a "quickstart" version linked below if anyone wants to try it out. Check out the "about" tab for a minimal manual in that case.
The grammar:
The grammar is ISO EBNF with a few exceptions. Exceptions (A matches B but not C) and comments are not supported. This also means that 1+ repetition is not supported. I have while prototyping not found any need for exceptions so I've not implemented support for it. Comments will probably be implemented as the grammar grows and need for documentation and explantion arises. This is of course a limitation in the validation tool and not a problem with the grammar.
Special forms are used to move "variables" out of the grammar. Enumerated items that are expected to change (or if there's just a whole bunch of them) reside in .special-files. This goes for things such as all the various types. This is to make it easier to inject new items without having to change the actual grammar. Will probably refactor keywords to use that format in the future as well.
Current status:
The overrule tool is "complete". Meaning I'm currently satified with how it works. There are improvements to be made but nothing that needs immediate attention.
The grammar itself is just getting started. It currently handles most keywords and some other arbitrarily chosen rules. Basically the easy stuff.
I've also been looking for other magic grammars. The only one I actually know about though is https://bitbucket.org/eswald/incantus/s ... 3/parsing/ . If anyone has something laying around I'd be interested in seeing it.
Other than that any help is welcome. It might be a bit early to ask for extra hands since there's not much to work on yet but advice and general comments are welcome too.
Links:
Overrule - application only
http://dl.dropbox.com/u/2771470/overrul ... dalone.jar
Overrule - "quickstart"
http://dl.dropbox.com/u/2771470/overrule/overrule.zip
cards.xml
viewtopic.php?f=27&t=1347
core.ebnf
https://github.com/karmag/loa-grammar
Overrule code
https://github.com/karmag/overrule
https://github.com/karmag/bana (dependency)
https://github.com/karmag/loa-util (dependency)
ISO EBNF (actually the final draft version)
http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf
EBNF on wikipedia
http://en.wikipedia.org/wiki/Extended_B ... 3Naur_Form