From 00692aa89e2e5a4068879fd8c10baf13abd43ff9 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 10 Jul 2018 03:43:14 -0700 Subject: [PATCH] Support for underscores --- schala-lang/src/ast.rs | 1 + schala-lang/src/lib.rs | 1 - schala-lang/src/parsing.rs | 19 ++++--------------- schala-repl/src/lib.rs | 7 ------- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/schala-lang/src/ast.rs b/schala-lang/src/ast.rs index df4a28f..315a216 100644 --- a/schala-lang/src/ast.rs +++ b/schala-lang/src/ast.rs @@ -132,6 +132,7 @@ pub struct Guard { #[derive(Debug, PartialEq, Clone)] pub enum Pattern { + Ignored, TuplePattern(Vec), Literal(PatternLiteral), TupleStruct(Rc, Vec), diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index f1d9481..1562ab5 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -79,7 +79,6 @@ fn parsing(_handle: &mut Schala, input: Vec, comp: Option<&mu let (ast, trace) = parsing::parse(input); comp.map(|comp| { - println!("DEBUG OPTS: {:?}", comp.cur_debug_options); //TODO need to control which of these debug stages get added let opt = comp.cur_debug_options.get(0).map(|s| s.clone()); match opt { diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index 15f6f59..e507b89 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -694,21 +694,6 @@ impl Parser { }); parse_method!(simple_pattern(&mut self) -> ParseResult { - /* - let name = self.identifier()?; - match self.peek() { - LParen => { - let tuple_members = delimited!(self, LParen, type_name, Comma, RParen); - Ok(TupleStruct(name, tuple_members)) - }, - LCurlyBrace => { - let typed_identifier_list = delimited!(self, LCurlyBrace, typed_identifier, Comma, RCurlyBrace); - Ok(Record(name, typed_identifier_list)) - }, - _ => Ok(UnitStruct(name)) - } - */ - Ok(match self.peek() { Identifier(_) => { let id = self.identifier()?; @@ -729,6 +714,10 @@ impl Parser { let Expression(expr_type, _) = self.number_literal()?; Pattern::Literal(PatternLiteral::NumPattern(expr_type)) }, + Underscore => { + self.next(); + Pattern::Ignored + }, other => return ParseError::new(&format!("{:?} is not a valid Pattern", other)) }) }); diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index f0932bf..bba5ecb 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -413,13 +413,6 @@ impl Repl { } writeln!(buf, "").unwrap(); - - /* - writeln!(buf, "exit | quit - exit the REPL").unwrap(); - writeln!(buf, "debug [show|hide] - show or hide debug info for a given pass").unwrap(); - writeln!(buf, "debug passes - display the names of all passes").unwrap(); - writeln!(buf, "lang [prev|next|go |show] - toggle to previous or next language, go to a specific language by name, or show all languages").unwrap(); - */ writeln!(buf, "Language-specific help for {}", lang.get_language_name()).unwrap(); writeln!(buf, "-----------------------").unwrap(); writeln!(buf, "{}", lang.custom_interpreter_directives_help()).unwrap();