Skip to content

Instantly share code, notes, and snippets.

@eignnx
Last active May 1, 2020 19:30
Show Gist options
  • Select an option

  • Save eignnx/d875c21f7b345567b0d95decdaca6636 to your computer and use it in GitHub Desktop.

Select an option

Save eignnx/d875c21f7b345567b0d95decdaca6636 to your computer and use it in GitHub Desktop.
A "Hello world" example for the `affix-grammar` sentence generator.
-- # Welcome to Affix Grammar!
-- Affix Grammar is a tool which lets you write grammars, and randomly generates sentences based on those grammars.
-- You can use it to:
-- - generate stories (kinda like Mad Libs),
-- - test out context-free grammars,
-- - test your knowledge of the grammar of a human language you're learning!
-- Here's a simple grammar which generates "hello world" sentences from different languages.
--
-- Click the `Generate` button a few times to see the sentences that are produced!
--
-- You can edit this grammar by clicking on the `Edit` tab.
rule start = hello_world.Language "(" + @Language + ")"
rule hello_world.Language =
.english -> "Hello, World!"
.spanish -> "¡Hola Mundo!"
.japanese -> "こんにちは世界!"
.arabic -> "مرحبا بالعالم!"
.indonesian -> "Salamu, Dunia!"
.uyghur -> "ياخشىمۇسىز دۇنيا!"
.greek -> "Γειά σου Κόσμε!"
.ukrainian -> "Привіт Світ!"
.thai -> "สวัสดีชาวโลก!"
.french -> "Bonjour le monde!"
data Language
= english ("English")
| spanish ("Spanish")
| japanese ("Japanese")
| arabic ("Arabic")
| indonesian ("Indonesian")
| uyghur ("Uyghur")
| greek ("Greek")
| ukrainian ("Ukranian")
| thai ("Thai")
| french ("French")
-- # Learn
-- Want to learn how to write your own grammars? For a beginners tutorial, [click here](https://affix-grammar.netlify.app?gist=5658476af6dbd36dbc7f73594976e8dd)!
-- # About the Project
-- Affix Grammar (name subject to change) was heavily inspired by [Dr. Kate Compton](https://github.com/galaxykate)'s [Tracery Project](https://github.com/galaxykate/tracery), and incorporates additional ideas from the paper [Affix Grammars for Natural Languages](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.53.5264&rep=rep1&type=pdf) about [Affix Grammars](https://en.m.wikipedia.org/wiki/Affix_grammar).
--
-- The project repository is located [here](https://github.com/eignnx/affix-grammar).
--
-- ## Technical Details
-- The Affix Grammar parsing and generation engine is written in the [Rust](https://rust-lang.org) language and compiled to [Webassembly](https://webassembly.org/). Markdown rendering is done by a Rust library called [pulldown-cmark](https://crates.io/crates/pulldown-cmark). This frontend is written in [Vue.js](https://vuejs.org/), and the text editor is [Ace](https://ace.c9.io/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment