Function flexi_parse::parse_string
source · pub fn parse_string<T: Parse>(source: String) -> Result<T>Expand description
Scans and parses the given string into the syntax tree node T.
This function ignores all whitespace.
Examples found in repository?
More examples
examples/lox/main.rs (lines 730-769)
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
fn main() {
let ast: Ast = pretty_unwrap(parse_string(
r#"
var x = 5;
var y = "hello";
x = 6;
y = 4.0;
fun add(x, y) {
return x + y;
}
print(add(x, y));
class Cake {
init(flavour) {
this.flavour = flavour;
}
taste() {
var adjective = "delicious";
print "The " + this.flavour + " cake is " + adjective + "!";
}
}
class ChocolateCake < Cake {
init() {
this.flavour = "Chocolate";
}
taste() {
super.taste();
print "Mmm, chocolatey!";
}
}
var cake = ChocolateCake();
cake.taste();
"#
.to_string(),
));
pretty_unwrap(resolver::resolve(&ast));
pretty_unwrap(interpreter::interpret(ast));
}