Write examples and highlight queries
This commit is contained in:
parent
72af839102
commit
8a38790f57
7883
examples/assets/jq_data.json
Normal file
7883
examples/assets/jq_data.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -35,11 +35,11 @@ make_guess = function <current_room> {
|
||||
)
|
||||
} else {
|
||||
(output 'I accuse '
|
||||
+ (random suspects)
|
||||
+ ' in the '
|
||||
+ current_room
|
||||
+ ' with the '
|
||||
+ (random weapons)
|
||||
+ '!')
|
||||
+ (random suspects)
|
||||
+ ' in the '
|
||||
+ current_room
|
||||
+ ' with the '
|
||||
+ (random weapons)
|
||||
+ '!')
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
count = 1
|
||||
|
||||
while count <= 15 {
|
||||
mod_three = count % 3 == 0
|
||||
mod_five = count % 5 == 0
|
||||
divides_by_3 = count % 3 == 0
|
||||
divides_by_5 = count % 5 == 0
|
||||
|
||||
if mod_three && mod_five {
|
||||
if divides_by_3 && divides_by_5 {
|
||||
(output 'fizzbuzz')
|
||||
} else if mod_three {
|
||||
} else if divides_by_3 {
|
||||
(output 'fizz')
|
||||
} else if mod_five {
|
||||
} else if divides_by_5 {
|
||||
(output 'buzz')
|
||||
} else {
|
||||
(output count)
|
||||
|
8
examples/jq_data.ds
Normal file
8
examples/jq_data.ds
Normal file
@ -0,0 +1,8 @@
|
||||
data = (from_json (read 'examples/assets/jq_data.json'))
|
||||
|
||||
transform commit_data in data {
|
||||
{
|
||||
message = commit_data.commit.message
|
||||
name = commit_data.commit.committer.name
|
||||
}
|
||||
}
|
@ -43,7 +43,11 @@ fn main() {
|
||||
};
|
||||
|
||||
match eval_result {
|
||||
Ok(value) => println!("{value}"),
|
||||
Ok(value) => {
|
||||
if !value.is_empty() {
|
||||
println!("{value}")
|
||||
}
|
||||
}
|
||||
Err(error) => eprintln!("{error}"),
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `()`, or returns`Err` if `self` is not a `Value::Tuple`.
|
||||
/// Returns `()`, or returns`Err` if `self` is not a `Value::Empty`.
|
||||
pub fn as_empty(&self) -> Result<()> {
|
||||
match self {
|
||||
Value::Empty => Ok(()),
|
||||
@ -201,7 +201,7 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an owned table, either by cloning or converting the inner value..
|
||||
/// Returns an owned table, either by cloning or converting the inner value.
|
||||
pub fn to_table(&self) -> Result<Table> {
|
||||
match self {
|
||||
Value::Table(table) => Ok(table.clone()),
|
||||
@ -399,13 +399,13 @@ impl Serialize for Value {
|
||||
Value::Integer(inner) => serializer.serialize_i64(*inner),
|
||||
Value::Boolean(inner) => serializer.serialize_bool(*inner),
|
||||
Value::List(inner) => {
|
||||
let mut tuple = serializer.serialize_tuple(inner.len())?;
|
||||
let mut list = serializer.serialize_tuple(inner.len())?;
|
||||
|
||||
for value in inner {
|
||||
tuple.serialize_element(value)?;
|
||||
list.serialize_element(value)?;
|
||||
}
|
||||
|
||||
tuple.end()
|
||||
list.end()
|
||||
}
|
||||
Value::Empty => todo!(),
|
||||
Value::Map(inner) => inner.serialize(serializer),
|
||||
@ -468,8 +468,8 @@ impl From<bool> for Value {
|
||||
}
|
||||
|
||||
impl From<Vec<Value>> for Value {
|
||||
fn from(tuple: Vec<Value>) -> Self {
|
||||
Value::List(tuple)
|
||||
fn from(vec: Vec<Value>) -> Self {
|
||||
Value::List(vec)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,71 @@
|
||||
(expression) @expression
|
||||
(value) @value
|
||||
(comment) @comment
|
||||
(operator) @operator
|
||||
(identifier) @constant
|
||||
(identifier) @identifier
|
||||
(value) @value
|
||||
(string) @string
|
||||
|
||||
(integer) @number
|
||||
(float) @float
|
||||
|
||||
(yield) @keyword
|
||||
(chain) @keyword
|
||||
[
|
||||
(integer)
|
||||
(float)
|
||||
] @number
|
||||
|
||||
(function) @function
|
||||
(tool) @function.builtin
|
||||
|
||||
(empty) @null
|
||||
(boolean) @boolean
|
||||
(list) @list
|
||||
|
||||
"," @punctuation.delimiter
|
||||
|
||||
[
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
(assignment_operator)
|
||||
(logic_operator)
|
||||
(math_operator)
|
||||
] @operator
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"for"
|
||||
"transform"
|
||||
"in"
|
||||
"function"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"assert"
|
||||
"assert_equal"
|
||||
"download"
|
||||
"help"
|
||||
"length"
|
||||
"output"
|
||||
"output_error"
|
||||
"type"
|
||||
"workdir"
|
||||
"append"
|
||||
"metadata"
|
||||
"move"
|
||||
"read"
|
||||
"remove"
|
||||
"write"
|
||||
"bash"
|
||||
"fish"
|
||||
"raw"
|
||||
"sh"
|
||||
"zsh"
|
||||
"random"
|
||||
"random_boolean"
|
||||
"random_float"
|
||||
"random_integer"
|
||||
"columns"
|
||||
"rows"
|
||||
] @function.builtin
|
Loading…
Reference in New Issue
Block a user