diff --git a/README.md b/README.md index 4f7341b..3b5f035 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ small enough you can learn it in minutes. It was born out of the following frust ## What Corn Is Not Corn is not a full programming language and does not try to be. -There are no dynamic variables, there is no interpolation and there are no statement blocks. +There are no dynamic variables, there are no operations and there are no statement blocks. Likewise, Corn is not a data exchange format. Unlike JSON or YAML or TOML, you cannot serialize code back into Corn. @@ -436,6 +436,8 @@ Evaluates to: } ``` +To use a literal dollar, you can escape with `\$`. For example, `\$subject`. + #### Merging Somtimes you want to re-use an object or array to compose a larger object/array. diff --git a/assets/inputs/string_interpolation.corn b/assets/inputs/string_interpolation.corn index ce27125..465426e 100644 --- a/assets/inputs/string_interpolation.corn +++ b/assets/inputs/string_interpolation.corn @@ -3,4 +3,5 @@ let { $subject = "world" } in { foo = "$greeting, $subject" + bar = "\$escaped" } diff --git a/assets/outputs/json/string_interpolation.json b/assets/outputs/json/string_interpolation.json index e92af90..8b6aea8 100644 --- a/assets/outputs/json/string_interpolation.json +++ b/assets/outputs/json/string_interpolation.json @@ -1,3 +1,4 @@ { + "bar": "$escaped", "foo": "hello, world" } diff --git a/assets/outputs/toml/string_interpolation.toml b/assets/outputs/toml/string_interpolation.toml index dac015a..c0af6cf 100644 --- a/assets/outputs/toml/string_interpolation.toml +++ b/assets/outputs/toml/string_interpolation.toml @@ -1,2 +1,3 @@ +bar = "$escaped" foo = "hello, world" diff --git a/assets/outputs/yaml/string_interpolation.yml b/assets/outputs/yaml/string_interpolation.yml index be478b0..4be0318 100644 --- a/assets/outputs/yaml/string_interpolation.yml +++ b/assets/outputs/yaml/string_interpolation.yml @@ -1,2 +1,3 @@ +bar: $escaped foo: hello, world diff --git a/libcorn/src/grammar.pest b/libcorn/src/grammar.pest index 7a40ba4..af09b5d 100644 --- a/libcorn/src/grammar.pest +++ b/libcorn/src/grammar.pest @@ -49,7 +49,7 @@ string_val = ${ (input | char)* } char = { !("\"" | "\\") ~ ANY - | "\\" ~ ("\"" | "\\" | "n" | "r" | "t") + | "\\" ~ ("\"" | "\\" | "n" | "r" | "t" | "$") | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4}) } @@ -73,7 +73,7 @@ float = @{ ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)? } -input = ${ "$" ~ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")+ } +input = ${ !"\\" ~ "$" ~ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")+ } assignment = { input ~ "=" ~ value } diff --git a/libcorn/src/parser.rs b/libcorn/src/parser.rs index 4158b5c..4cdc39c 100644 --- a/libcorn/src/parser.rs +++ b/libcorn/src/parser.rs @@ -142,6 +142,7 @@ impl<'a> CornParser<'a> { 'r' => '\r', 't' => '\t', '"' => '\"', + '$' => '$', '\\' => '\\', _ => unreachable!(), };