Skip to content

Commit

Permalink
Add more obscure stuff for lulz
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed May 4, 2024
1 parent 58c3060 commit 274daa7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions documentation/advanced-dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,11 @@ Pitch can be declared as a period of oscillation, but it's coearced to Hz to pre
E.g. `C4 = 10ms` has the same effect as `C4 = 100 Hz`.

### Obscure types
| Type | Literal | Meaning |
| ------ | ------- | ------------------------------------------------------ |
| Second | `1s` | Inverse of `1Hz` i.e. `1s * 1Hz` evaluates to `1` |
| Jorp | `` | Geometric inverse of `c` i.e. `` is equal to `<1200]` |
| Type | Literal | Meaning |
| ------------ | ------- | ------------------------------------------------------ |
| Second | `1s` | Inverse of `1Hz` i.e. `1s * 1Hz` evaluates to `1` |
| Jorp | `` | Geometric inverse of `c` i.e. `` is equal to `<1200]` |
| Pilcrowspoob | `` | Geometric inverse of `logarithmic(1Hz)` |

### Obscure operations
| Name | Linear | Result | Logarithmic | Result |
Expand Down
1 change: 1 addition & 0 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export function expressionToString(node: Expression) {
case 'CentsLiteral':
case 'CentLiteral':
case 'ReciprocalCentLiteral':
case 'ReciprocalLogarithmicHertzLiteral':
case 'FJS':
case 'AspiringFJS':
case 'AbsoluteFJS':
Expand Down
7 changes: 7 additions & 0 deletions src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export type SecondLiteral = {
prefix: MetricPrefix | BinaryPrefix;
};

export type ReciprocalLogarithmicHertzLiteral = {
type: 'ReciprocalLogarithmicHertzLiteral';
};

export type FJS = {
type: 'FJS';
ups: number;
Expand Down Expand Up @@ -245,6 +249,7 @@ export type IntervalLiteral =
| AspiringAbsoluteFJS
| HertzLiteral
| SecondLiteral
| ReciprocalLogarithmicHertzLiteral
| MonzoLiteral
| ValLiteral
| SparseOffsetVal
Expand Down Expand Up @@ -958,6 +963,8 @@ export function literalToString(literal: IntervalLiteral) {
return `${literal.real ? 'r' : ''}¢`;
case 'ReciprocalCentLiteral':
return '€';
case 'ReciprocalLogarithmicHertzLiteral':
return '¶';
case 'FJS':
return formatFJS(literal);
case 'AbsoluteFJS':
Expand Down
4 changes: 4 additions & 0 deletions src/grammars/sonic-weave.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ Quantity
= WartsLiteral
/ SparseOffsetVal
/ ReciprocalCentLiteral
/ ReciprocalLogarithmicHertzLiteral
/ MonzoLiteral
/ ValLiteral
/ DownExpression
Expand Down Expand Up @@ -1144,6 +1145,9 @@ SecondLiteral
ReciprocalCentLiteral
= '' { return { type: 'ReciprocalCentLiteral' }; }
ReciprocalLogarithmicHertzLiteral
= '' { return { type: 'ReciprocalLogarithmicHertzLiteral' }; }
NoneLiteral
= NoneToken { return { type: 'NoneLiteral' }; }
Expand Down
7 changes: 6 additions & 1 deletion src/parser/__tests__/expression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2336,8 +2336,13 @@ describe('Poor grammar / Fun with "<"', () => {
expect(sqrt2.valueOf()).toBeCloseTo(Math.SQRT2);
});

it('has string representation for the geometric inverse of the Hertz', () => {
it('has string representation for the geometric inverse of the logarithmic Hertz', () => {
const whatIsThis = evaluate('str(%logarithmic(1z))');
expect(whatIsThis).toBe('withEquave(<1]@Hz, 1 Hz)');
});

it('has a literal for the geometric inverse of the logarithmic Hertz', () => {
const {fraction} = parseSingle('¶ dot logarithmic(1z)');
expect(fraction).toBe('1');
});
});
5 changes: 5 additions & 0 deletions src/parser/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const KIBI_MONZO = new TimeMonzo(ZERO, [F(10)]);
const CENT_MONZO = new TimeMonzo(ZERO, [F(1, 1200)]);
const CENT_REAL = new TimeReal(0, 1.0005777895065548);
const RECIPROCAL_CENT_MONZO = new TimeMonzo(ZERO, [F(1200)]);
const HERTZ_MONZO = new TimeMonzo(NEGATIVE_ONE, []);

function typesCompatible(
a: IntervalLiteral | undefined,
Expand Down Expand Up @@ -325,6 +326,10 @@ export class ExpressionVisitor {
return new Val(RECIPROCAL_CENT_MONZO, TWO_MONZO, {
type: 'ReciprocalCentLiteral',
});
case 'ReciprocalLogarithmicHertzLiteral':
return new Val(HERTZ_MONZO, HERTZ_MONZO, {
type: 'ReciprocalLogarithmicHertzLiteral',
});
case 'TrueLiteral':
return true;
case 'FalseLiteral':
Expand Down

0 comments on commit 274daa7

Please sign in to comment.