Start new example; Start new syntax features
This commit is contained in:
parent
eaf26fec5e
commit
ca72fe04f1
28
examples/guessing_game.ds
Normal file
28
examples/guessing_game.ds
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# This is a Dust version of an example from the Rust Book.
|
||||||
|
#
|
||||||
|
# https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
|
||||||
|
|
||||||
|
output("Guess the number.")
|
||||||
|
|
||||||
|
secret_number = int:random_range(0..=100);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
output("Please input your guess.")
|
||||||
|
|
||||||
|
input = io::stdin():expect("Failed to read line.")
|
||||||
|
guess = int:parse(input);
|
||||||
|
|
||||||
|
output("You guessed: " + guess)
|
||||||
|
|
||||||
|
match cmp(guess, secret_number) {
|
||||||
|
Ordering::Less -> output("Too small!"),
|
||||||
|
Ordering::Greater -> output("Too big!"),
|
||||||
|
Ordering::Equal -> {
|
||||||
|
output("You win!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,6 +31,7 @@ module.exports = grammar({
|
|||||||
$.for,
|
$.for,
|
||||||
$.if_else,
|
$.if_else,
|
||||||
$.index_assignment,
|
$.index_assignment,
|
||||||
|
$.break_loop,
|
||||||
$.match,
|
$.match,
|
||||||
$.pipe,
|
$.pipe,
|
||||||
$.while,
|
$.while,
|
||||||
@ -327,6 +328,12 @@ module.exports = grammar({
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
break_loop: $ =>
|
||||||
|
seq(
|
||||||
|
'loop',
|
||||||
|
$.block,
|
||||||
|
),
|
||||||
|
|
||||||
while: $ =>
|
while: $ =>
|
||||||
seq(
|
seq(
|
||||||
'while',
|
'while',
|
||||||
|
@ -1,20 +1,33 @@
|
|||||||
(expression) @expression
|
(statement) @statement
|
||||||
|
[
|
||||||
|
(expression)
|
||||||
|
(function_expression)
|
||||||
|
(index_expression)
|
||||||
|
] @expression
|
||||||
(value) @value
|
(value) @value
|
||||||
(identifier) @variable
|
(identifier) @variable
|
||||||
|
|
||||||
(value) @value
|
(value) @value
|
||||||
(string) @string
|
(string) @string
|
||||||
|
|
||||||
[
|
[
|
||||||
(integer)
|
(integer)
|
||||||
(float)
|
(float)
|
||||||
] @number
|
] @number
|
||||||
|
[
|
||||||
(function) @function
|
(command)
|
||||||
|
(function)
|
||||||
|
] @function
|
||||||
|
(range) @range
|
||||||
(boolean) @boolean
|
(boolean) @boolean
|
||||||
(list) @list
|
(list) @list
|
||||||
|
(map) @map
|
||||||
|
|
||||||
["," ":" ";"] @punctuation.delimiter
|
(struct_definition) @struct
|
||||||
|
(enum_definition) @enum
|
||||||
|
|
||||||
|
(block) @block
|
||||||
|
|
||||||
|
["," ";"] @punctuation.delimiter
|
||||||
|
|
||||||
[
|
[
|
||||||
"["
|
"["
|
||||||
@ -27,30 +40,33 @@
|
|||||||
")"
|
")"
|
||||||
] @punctuation.bracket
|
] @punctuation.bracket
|
||||||
|
|
||||||
[
|
(type) @type
|
||||||
(type)
|
|
||||||
(type_specification)
|
|
||||||
] @type
|
|
||||||
|
|
||||||
(assignment_operator) @operator.assignment
|
(assignment_operator) @operator.assignment
|
||||||
(logic_operator) @operator.logic
|
(logic_operator) @operator.logic
|
||||||
(math_operator) @operator.math
|
(math_operator) @operator.math
|
||||||
|
|
||||||
[
|
[
|
||||||
|
"as"
|
||||||
"async"
|
"async"
|
||||||
|
"break"
|
||||||
"else"
|
"else"
|
||||||
"else if"
|
"else if"
|
||||||
|
"enum"
|
||||||
"false"
|
"false"
|
||||||
"for"
|
"for"
|
||||||
"if"
|
"if"
|
||||||
"in"
|
"in"
|
||||||
|
"loop"
|
||||||
"match"
|
"match"
|
||||||
"self"
|
"return"
|
||||||
|
"struct"
|
||||||
"true"
|
"true"
|
||||||
"while"
|
"while"
|
||||||
"->"
|
"->"
|
||||||
"=>"
|
":"
|
||||||
|
"::"
|
||||||
|
"^"
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
(built_in_function) @function.builtin
|
|
||||||
(function_call) @function.call
|
(function_call) @function.call
|
||||||
|
Loading…
Reference in New Issue
Block a user