Skip to content

Instantly share code, notes, and snippets.

View eignnx's full-sized avatar

eignnx eignnx

View GitHub Profile
fn slice_of_slice<'pool, 'slice, 'ret>(
pool: &'pool [usize],
slice: &'slice [usize],
) -> &'ret [usize]
where
'pool: 'slice, // `pool` outlives `slice`
'slice: 'ret, // `slice` outlives the return value
{
// Most of this is bullshit so that both `slice` and `pool` are used.
@eignnx
eignnx / hello-world.affix
Last active May 1, 2020 19:30
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!
@eignnx
eignnx / lesson1.affix
Last active April 1, 2020 22:40
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.
@eignnx
eignnx / lesson2.affix
Last active April 2, 2020 00:07
Lesson 2 of the `affix-grammar` beginner guide.
-- # Affix Grammar Tutorial: Lesson 2
-- ### Joining Words Together
-- Check out this grammar 👇
rule start = "These" "are" "a" "few" things + "!"
rule things = "words" | "sentence elements" | "lexemes"
-- When two sentence elements (like `"quoted text"` or `rule_names`) are placed next to each other, they are implicitly joined together and separated by a space (" "). So writing:
-- > `"Stop" "thief!"`
@eignnx
eignnx / lesson3.affix
Last active April 2, 2020 00:06
Lesson 3 of the `affix-grammar` beginner guide.
-- # Beginner Tutorial: Lesson 3
-- ### Data Variants
-- A rule can be parameterized by what's called a "data variant." Let's define one to illustrate.
data Gender = nonbinary | feminine | neutral
-- An instance of `Gender` can be one of the three possibilities listed.
--
-- *Aside: this isn't an exhaustive list of genders (that would probably be infinite), just some of the most common in English. See the exercise at the end!*
@eignnx
eignnx / semantic_nom_whitespace.rs
Last active June 22, 2021 22:42
An idea for how to handle whitespace in Rust's `nom` parser-combinator library.
/// A module for parsing whitespace. Takes into account comments too.
///
/// # Module Outline
/// - mod space
/// - fn comment
/// - mod allowed
/// - fn here
/// - fn after
/// - fn before
/// - fn around
-- # Beginners Tutorial: Lesson 4
-- ### Data Variant Aliases
-- In this lesson you'll learn how to display data variants in user-friendly ways.
-- Say you wanted to write a story about a character.
data Character = val | sam | penny
rule story = name.Character "went to the store."
-- # Generating Center Embeddings
-- [This wikipedia article](https://en.wikipedia.org/wiki/Center_embedding) is about a kind of sentence that is REALLY hard to understand. Click the "Generate" button in the top right to generate sentences!
rule start = center_embedding
rule center_embedding = subject verb_phrase + "."
rule verb_phrase
= "slept"
| "killed" subject
50 Ways to Leave Your Lover
Paul Simon
-----------------------------------CHORDS---------------------------------------
Cmaj7 = x35453 (close to barred C)
B7 = x24242 (barred)
D#dim = 23424x (kinda like barred B7, but add middle finger)
D/F# = 200232 (wrap thumb around onto lowest string @ fret #2)
G = 355433
--OPTION 1 (CURRENT SYNTAX)----
rule whatever1 = "something"
rule whatever2.Thing =
.thing1 -> "something 1"
.thing2 -> "something 2"
rule whatever3.Thing.Thing =
.thing1 {
.thing1 -> "something 1"