Skip to content

Instantly share code, notes, and snippets.

@eignnx
Last active April 1, 2020 22:40
Show Gist options
  • Save eignnx/5658476af6dbd36dbc7f73594976e8dd to your computer and use it in GitHub Desktop.
Save eignnx/5658476af6dbd36dbc7f73594976e8dd to your computer and use it in GitHub Desktop.
Lesson 1 of the `affix-grammar` beginner guide.
-- # Affix Grammar Tutorial: Lesson 1
-- Hi! Welcome to Affix Grammar!
-- ### What is it?
-- Affix Grammar lets you generate sentences, stories, textual patterns and more! It's kinda like Mad Libs.
-- Lets generate a simple sentence that has a few variations. An example of the kind of sentence we'll generate is:
-- > "Last Wednesday, Val went for a walk in the park after supper."
--
-- First, we'll define a "rule" called `start`. This will be the entry point to our grammar.
rule start = "Last Wednesday," character "went for a walk in" place "after supper."
-- Since we referenced them, we'll need to define two more rules, `character` and `place`.
rule character = "Sam" | "Val" | "Penny"
-- The character rule produces either Sam, Val, or Penny. Each of these three
-- are called "alternatives".
--
-- Now lets define the `place` rule.
rule place
= "the woods"
| "an abandoned parking lot"
| "the park"
| "the graveyard behind" place
-- This time we split each alternative onto separate lines. You can do this any time you feel it makes things more readable.
--
-- Also, notice that the last alternative references itself. This is fine, as long as there is at least one (1) **non-self-referential** alternative as well.
-- Ok! We've defined everything we need. Now press the `Generate` button to see the sentences that are produced!
-- ### Conclusion
-- Be sure to check out the `Edit` tab to see the full source file for this grammar. It includes lots of comments which are rendered to this webpage and are what what you're reading right now!
--
-- You're now ready to move on to [Lesson 2](https://affix-grammar.netlify.app?gist=d12b0e5b0c4e9b00015a82ad557e15f0)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment