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
@ -1,14 +1,14 @@
|
|||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
while count <= 15 {
|
while count <= 15 {
|
||||||
mod_three = count % 3 == 0
|
divides_by_3 = count % 3 == 0
|
||||||
mod_five = count % 5 == 0
|
divides_by_5 = count % 5 == 0
|
||||||
|
|
||||||
if mod_three && mod_five {
|
if divides_by_3 && divides_by_5 {
|
||||||
(output 'fizzbuzz')
|
(output 'fizzbuzz')
|
||||||
} else if mod_three {
|
} else if divides_by_3 {
|
||||||
(output 'fizz')
|
(output 'fizz')
|
||||||
} else if mod_five {
|
} else if divides_by_5 {
|
||||||
(output 'buzz')
|
(output 'buzz')
|
||||||
} else {
|
} else {
|
||||||
(output count)
|
(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 {
|
match eval_result {
|
||||||
Ok(value) => println!("{value}"),
|
Ok(value) => {
|
||||||
|
if !value.is_empty() {
|
||||||
|
println!("{value}")
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(error) => eprintln!("{error}"),
|
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<()> {
|
pub fn as_empty(&self) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Value::Empty => Ok(()),
|
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> {
|
pub fn to_table(&self) -> Result<Table> {
|
||||||
match self {
|
match self {
|
||||||
Value::Table(table) => Ok(table.clone()),
|
Value::Table(table) => Ok(table.clone()),
|
||||||
@ -399,13 +399,13 @@ impl Serialize for Value {
|
|||||||
Value::Integer(inner) => serializer.serialize_i64(*inner),
|
Value::Integer(inner) => serializer.serialize_i64(*inner),
|
||||||
Value::Boolean(inner) => serializer.serialize_bool(*inner),
|
Value::Boolean(inner) => serializer.serialize_bool(*inner),
|
||||||
Value::List(inner) => {
|
Value::List(inner) => {
|
||||||
let mut tuple = serializer.serialize_tuple(inner.len())?;
|
let mut list = serializer.serialize_tuple(inner.len())?;
|
||||||
|
|
||||||
for value in inner {
|
for value in inner {
|
||||||
tuple.serialize_element(value)?;
|
list.serialize_element(value)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple.end()
|
list.end()
|
||||||
}
|
}
|
||||||
Value::Empty => todo!(),
|
Value::Empty => todo!(),
|
||||||
Value::Map(inner) => inner.serialize(serializer),
|
Value::Map(inner) => inner.serialize(serializer),
|
||||||
@ -468,8 +468,8 @@ impl From<bool> for Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<Vec<Value>> for Value {
|
impl From<Vec<Value>> for Value {
|
||||||
fn from(tuple: Vec<Value>) -> Self {
|
fn from(vec: Vec<Value>) -> Self {
|
||||||
Value::List(tuple)
|
Value::List(vec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,71 @@
|
|||||||
(expression) @expression
|
(expression) @expression
|
||||||
(value) @value
|
(value) @value
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
(operator) @operator
|
(identifier) @identifier
|
||||||
(identifier) @constant
|
|
||||||
(value) @value
|
(value) @value
|
||||||
(string) @string
|
(string) @string
|
||||||
|
|
||||||
(integer) @number
|
[
|
||||||
(float) @float
|
(integer)
|
||||||
|
(float)
|
||||||
(yield) @keyword
|
] @number
|
||||||
(chain) @keyword
|
|
||||||
|
|
||||||
(function) @function
|
(function) @function
|
||||||
(tool) @function.builtin
|
|
||||||
|
|
||||||
(empty) @null
|
|
||||||
(boolean) @boolean
|
(boolean) @boolean
|
||||||
(list) @list
|
(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