Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add demo of indirection syntax to support ‘variable variables’ #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maetl
Copy link
Collaborator

@maetl maetl commented Nov 27, 2022

This adds new modifier syntax supporting a basic metaprogramming feature where the result of a template expansion is itself used as a template expansion term rather than being concatenated into the result.

eg:

const varvar = calyx.grammar({
  start: "{~name} from the {~location}",
  "location": "{setting}",
  "name": "{setting}_names",
  setting: ["fantasy", "scifi", "cyberpunk"],
  fantasy: ["tower", "dungeon", "village"],
  scifi: ["starship", "mining colony", "ringworld"],
  cyberpunk: ["neon city", "pharma lab"],
  fantasy_names: ["Undin", "Mirielye", "Edhen", "Burga"],
  scifi_names: ["Raige", "Enjan", "U'Krada", "Chrotha"],
  cyberpunk_names: ["Barick", "Zechiel", "Golden Static", "Citizen Death"]
});

const result = varvar.generate();

This adds new modifier syntax supporting a basic metaprogramming feature
where the result of a template expansion is itself used as a template
expansion term rather than being concatenated into the result.

eg:

```js
const varvar = calyx.grammar({
  start: "{~name} from the {~location}",
  "location": "{setting}",
  "name": "{setting}_names",
  setting: ["fantasy", "scifi", "cyberpunk"],
  fantasy: ["tower", "dungeon", "village"],
  scifi: ["starship", "mining colony", "ringworld"],
  cyberpunk: ["neon city", "pharma lab"],
  fantasy_names: ["Undin", "Mirielye", "Edhen", "Burga"],
  scifi_names: ["Raige", "Enjan", "U'Krada", "Chrotha"],
  cyberpunk_names: ["Barick", "Zechiel", "Golden Static", "Citizen Death"]
});

const result = varvar.generate();
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant