[BREAKING] Feat: quotation is now using ()
This commit is contained in:
@@ -31,7 +31,7 @@ fn tokenize(input: &str) -> Vec<Token> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if c == '(' || c == ')' {
|
||||
if c == '{' || c == '}' {
|
||||
chars.next();
|
||||
continue;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
|
||||
Token::Str(s, span) => ops.push(Op::PushStr(Arc::from(s.as_str()), Some(*span))),
|
||||
Token::Word(w, span) => {
|
||||
let word = w.as_str();
|
||||
if word == "{" {
|
||||
if word == "(" {
|
||||
let (quote_ops, consumed, end_span) =
|
||||
compile_quotation(&tokens[i + 1..], dict)?;
|
||||
i += consumed;
|
||||
@@ -142,8 +142,8 @@ fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
|
||||
end: end_span.end,
|
||||
};
|
||||
ops.push(Op::Quotation(Arc::from(quote_ops), Some(body_span)));
|
||||
} else if word == "}" {
|
||||
return Err("unexpected }".into());
|
||||
} else if word == ")" {
|
||||
return Err("unexpected )".into());
|
||||
} else if word == "[" {
|
||||
let (bracket_ops, consumed, end_span) =
|
||||
compile_bracket(&tokens[i + 1..], dict)?;
|
||||
@@ -203,8 +203,8 @@ fn compile_quotation(
|
||||
for (i, tok) in tokens.iter().enumerate() {
|
||||
if let Token::Word(w, _) = tok {
|
||||
match w.as_str() {
|
||||
"{" => depth += 1,
|
||||
"}" => {
|
||||
"(" => depth += 1,
|
||||
")" => {
|
||||
depth -= 1;
|
||||
if depth == 0 {
|
||||
end_idx = Some(i);
|
||||
@@ -216,7 +216,7 @@ fn compile_quotation(
|
||||
}
|
||||
}
|
||||
|
||||
let end_idx = end_idx.ok_or("missing }")?;
|
||||
let end_idx = end_idx.ok_or("missing )")?;
|
||||
let end_span = match &tokens[end_idx] {
|
||||
Token::Word(_, span) => *span,
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -502,7 +502,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Logic",
|
||||
stack: "(true-quot false-quot bool --)",
|
||||
desc: "Execute true-quot if true, else false-quot",
|
||||
example: "{ 1 } { 2 } coin ifelse",
|
||||
example: "( 1 ) ( 2 ) coin ifelse",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -512,7 +512,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Logic",
|
||||
stack: "(..quots n --)",
|
||||
desc: "Execute nth quotation (0-indexed)",
|
||||
example: "{ 1 } { 2 } { 3 } 2 select => 3",
|
||||
example: "( 1 ) ( 2 ) ( 3 ) 2 select => 3",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
@@ -522,7 +522,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Logic",
|
||||
stack: "(quot bool --)",
|
||||
desc: "Execute quotation if true",
|
||||
example: "{ 2 distort } 0.5 chance ?",
|
||||
example: "( 2 distort ) 0.5 chance ?",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -532,7 +532,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Logic",
|
||||
stack: "(quot bool --)",
|
||||
desc: "Execute quotation if false",
|
||||
example: "{ 1 distort } 0.5 chance !?",
|
||||
example: "( 1 distort ) 0.5 chance !?",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -542,7 +542,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Logic",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation unconditionally",
|
||||
example: "{ 2 * } apply",
|
||||
example: "( 2 * ) apply",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -553,7 +553,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Control",
|
||||
stack: "(n quot --)",
|
||||
desc: "Execute quotation n times, @i holds current index",
|
||||
example: "4 { @i . } times => 0 1 2 3",
|
||||
example: "4 ( @i . ) times => 0 1 2 3",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot prob --)",
|
||||
desc: "Execute quotation with probability (0.0-1.0)",
|
||||
example: "{ 2 distort } 0.75 chance",
|
||||
example: "( 2 distort ) 0.75 chance",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -70,7 +70,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot pct --)",
|
||||
desc: "Execute quotation with probability (0-100)",
|
||||
example: "{ 2 distort } 75 prob",
|
||||
example: "( 2 distort ) 75 prob",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -150,7 +150,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Always execute quotation",
|
||||
example: "{ 2 distort } always",
|
||||
example: "( 2 distort ) always",
|
||||
compile: Probability(1.0),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -160,7 +160,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Never execute quotation",
|
||||
example: "{ 2 distort } never",
|
||||
example: "( 2 distort ) never",
|
||||
compile: Probability(0.0),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -170,7 +170,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 75% of the time",
|
||||
example: "{ 2 distort } often",
|
||||
example: "( 2 distort ) often",
|
||||
compile: Probability(0.75),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -180,7 +180,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 50% of the time",
|
||||
example: "{ 2 distort } sometimes",
|
||||
example: "( 2 distort ) sometimes",
|
||||
compile: Probability(0.5),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -190,7 +190,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 25% of the time",
|
||||
example: "{ 2 distort } rarely",
|
||||
example: "( 2 distort ) rarely",
|
||||
compile: Probability(0.25),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -200,7 +200,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 10% of the time",
|
||||
example: "{ 2 distort } almostNever",
|
||||
example: "( 2 distort ) almostNever",
|
||||
compile: Probability(0.1),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -210,7 +210,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 90% of the time",
|
||||
example: "{ 2 distort } almostAlways",
|
||||
example: "( 2 distort ) almostAlways",
|
||||
compile: Probability(0.9),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -221,7 +221,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot n --)",
|
||||
desc: "Execute quotation every nth iteration",
|
||||
example: "{ 2 distort } 4 every",
|
||||
example: "( 2 distort ) 4 every",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -231,7 +231,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot n --)",
|
||||
desc: "Execute quotation on all iterations except every nth",
|
||||
example: "{ 2 distort } 4 except",
|
||||
example: "( 2 distort ) 4 except",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -241,7 +241,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot n offset --)",
|
||||
desc: "Execute quotation every nth iteration with phase offset",
|
||||
example: "{ snare } 4 2 every+ => fires at iter 2, 6, 10...",
|
||||
example: "( snare ) 4 2 every+ => fires at iter 2, 6, 10...",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -251,7 +251,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot n offset --)",
|
||||
desc: "Skip quotation every nth iteration with phase offset",
|
||||
example: "{ snare } 4 2 except+ => skips at iter 2, 6, 10...",
|
||||
example: "( snare ) 4 2 except+ => skips at iter 2, 6, 10...",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -261,7 +261,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot k n --)",
|
||||
desc: "Execute quotation using Euclidean distribution over step runs",
|
||||
example: "{ 2 distort } 3 8 bjork",
|
||||
example: "( 2 distort ) 3 8 bjork",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -271,7 +271,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Time",
|
||||
stack: "(quot k n --)",
|
||||
desc: "Execute quotation using Euclidean distribution over pattern iterations",
|
||||
example: "{ 2 distort } 3 8 pbjork",
|
||||
example: "( 2 distort ) 3 8 pbjork",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
@@ -456,7 +456,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Desktop",
|
||||
stack: "(-- bool)",
|
||||
desc: "1 when mouse button held, 0 otherwise",
|
||||
example: "mdown { \"crash\" s . } ?",
|
||||
example: "mdown ( \"crash\" s . ) ?",
|
||||
compile: Context("mdown"),
|
||||
varargs: false,
|
||||
},
|
||||
@@ -487,7 +487,7 @@ pub(super) const WORDS: &[Word] = &[
|
||||
category: "Generator",
|
||||
stack: "(quot n -- results...)",
|
||||
desc: "Execute quotation n times, push all results",
|
||||
example: "{ 1 6 rand } 4 gen => 4 random values",
|
||||
example: "( 1 6 rand ) 4 gen => 4 random values",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user