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,
|
||||
$.if_else,
|
||||
$.index_assignment,
|
||||
$.break_loop,
|
||||
$.match,
|
||||
$.pipe,
|
||||
$.while,
|
||||
@ -327,6 +328,12 @@ module.exports = grammar({
|
||||
),
|
||||
),
|
||||
|
||||
break_loop: $ =>
|
||||
seq(
|
||||
'loop',
|
||||
$.block,
|
||||
),
|
||||
|
||||
while: $ =>
|
||||
seq(
|
||||
'while',
|
||||
|
@ -1,20 +1,33 @@
|
||||
(expression) @expression
|
||||
(statement) @statement
|
||||
[
|
||||
(expression)
|
||||
(function_expression)
|
||||
(index_expression)
|
||||
] @expression
|
||||
(value) @value
|
||||
(identifier) @variable
|
||||
|
||||
(value) @value
|
||||
(string) @string
|
||||
|
||||
[
|
||||
(integer)
|
||||
(float)
|
||||
] @number
|
||||
|
||||
(function) @function
|
||||
|
||||
[
|
||||
(command)
|
||||
(function)
|
||||
] @function
|
||||
(range) @range
|
||||
(boolean) @boolean
|
||||
(list) @list
|
||||
(map) @map
|
||||
|
||||
["," ":" ";"] @punctuation.delimiter
|
||||
(struct_definition) @struct
|
||||
(enum_definition) @enum
|
||||
|
||||
(block) @block
|
||||
|
||||
["," ";"] @punctuation.delimiter
|
||||
|
||||
[
|
||||
"["
|
||||
@ -27,30 +40,33 @@
|
||||
")"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
(type)
|
||||
(type_specification)
|
||||
] @type
|
||||
(type) @type
|
||||
|
||||
(assignment_operator) @operator.assignment
|
||||
(logic_operator) @operator.logic
|
||||
(math_operator) @operator.math
|
||||
|
||||
[
|
||||
"as"
|
||||
"async"
|
||||
"break"
|
||||
"else"
|
||||
"else if"
|
||||
"enum"
|
||||
"false"
|
||||
"for"
|
||||
"if"
|
||||
"in"
|
||||
"loop"
|
||||
"match"
|
||||
"self"
|
||||
"return"
|
||||
"struct"
|
||||
"true"
|
||||
"while"
|
||||
"->"
|
||||
"=>"
|
||||
":"
|
||||
"::"
|
||||
"^"
|
||||
] @keyword
|
||||
|
||||
(built_in_function) @function.builtin
|
||||
(function_call) @function.call
|
||||
|
Loading…
Reference in New Issue
Block a user