Make tests pass by using multiple-k lookahead

This commit is contained in:
greg 2019-06-14 02:28:14 -07:00
parent ccdc02bbd0
commit 71386be80e
1 changed files with 15 additions and 15 deletions

View File

@ -10,7 +10,7 @@
//! //!
//! ## Top level structure //! ## Top level structure
//! //!
//! ``` //! ```text
//! program := (statement delimiter)* EOF //! program := (statement delimiter)* EOF
//! delimiter := NEWLINE | ";" //! delimiter := NEWLINE | ";"
//! statement := expression | declaration //! statement := expression | declaration
@ -20,7 +20,7 @@
//! ## Declarations //! ## Declarations
//! //!
//! ### Types //! ### Types
//! ``` //! ```text
//! type_declaration := "type" type_declaration_body //! type_declaration := "type" type_declaration_body
//! type_declaration_body := "alias" type_alias | "mut"? type_singleton_name "=" type_body //! type_declaration_body := "alias" type_alias | "mut"? type_singleton_name "=" type_body
//! type_alias := IDENTIFIER "=" type_name //! type_alias := IDENTIFIER "=" type_name
@ -31,7 +31,7 @@
//! ``` //! ```
//! ### Functions //! ### Functions
//! //!
//! ``` //! ```text
//! func_declaration := func_signature func_body //! func_declaration := func_signature func_body
//! func_body := ε | nonempty_func_body //! func_body := ε | nonempty_func_body
//! nonempty_func_body := "{" (statement delimiter)* "}" //! nonempty_func_body := "{" (statement delimiter)* "}"
@ -42,11 +42,11 @@
//! ``` //! ```
//! //!
//! ### Variable bindings //! ### Variable bindings
//! ```binding_declaration := "let" "mut"? IDENTIFIER "=" expresion``` //! ```text binding_declaration := "let" "mut"? IDENTIFIER "=" expresion```
//! //!
//! ### Interfaces //! ### Interfaces
//! //!
//! ``` //! ```text
//! interface_declaration := "interface" type_singleton_name signature_block //! interface_declaration := "interface" type_singleton_name signature_block
//! impl_declaration := "impl" type_singleton_name decl_block | "impl" type_singleton_name "for" type_name decl_block //! impl_declaration := "impl" type_singleton_name decl_block | "impl" type_singleton_name "for" type_name decl_block
//! decl_block := "{" (func_declaration)* "}" //! decl_block := "{" (func_declaration)* "}"
@ -55,7 +55,7 @@
//! //!
//! ### Type Annotations //! ### Type Annotations
//! //!
//! ``` //! ```text
//! type_anno := ":" type_name //! type_anno := ":" type_name
//! type_name := type_singleton_name | "(" type_names ")" //! type_name := type_singleton_name | "(" type_names ")"
//! type_names := ε | type_name (, type_name)* //! type_names := ε | type_name (, type_name)*
@ -64,7 +64,7 @@
//! ``` //! ```
//! //!
//! ## Expressions //! ## Expressions
//! ``` //! ```text
//! expression := precedence_expr type_anno+ //! expression := precedence_expr type_anno+
//! precedence_expr := prefix_expr //! precedence_expr := prefix_expr
//! prefix_expr := prefix_op call_expr //! prefix_expr := prefix_op call_expr
@ -79,7 +79,7 @@
//! //!
//! ### Primary expressions //! ### Primary expressions
//! //!
//! ``` //! ```text
//! list_expr := "[" (expression, ",")* "]" //! list_expr := "[" (expression, ",")* "]"
//! lambda_expr := "\\" lambda_param_list type_anno+ nonempty_func_body //! lambda_expr := "\\" lambda_param_list type_anno+ nonempty_func_body
//! lambda_param_list := formal_param_list | formal_param //! lambda_param_list := formal_param_list | formal_param
@ -89,7 +89,7 @@
//! ``` //! ```
//! //!
//! ## Literals //! ## Literals
//! ``` //! ```text
//! literal := "true" | "false" | number_literal | STR_LITERAL //! literal := "true" | "false" | number_literal | STR_LITERAL
//! named_struct := IDENTIFIER record_block //! named_struct := IDENTIFIER record_block
//! record_block := "{" (record_entry, ",")* | "}" //TODO support anonymus structs, update syntax //! record_block := "{" (record_entry, ",")* | "}" //TODO support anonymus structs, update syntax
@ -103,7 +103,7 @@
//! ``` //! ```
//! //!
//! ### Patterns //! ### Patterns
//! ``` //! ```text
//! pattern := "(" (pattern, ",")* ")" | simple_pattern //! pattern := "(" (pattern, ",")* ")" | simple_pattern
//! simple_pattern := pattern_literal | record_pattern | tuple_struct_pattern //! simple_pattern := pattern_literal | record_pattern | tuple_struct_pattern
//! pattern_literal := "true" | "false" | signed_number_literal | STR_LITERAL | IDENTIFIER //! pattern_literal := "true" | "false" | signed_number_literal | STR_LITERAL | IDENTIFIER
@ -114,7 +114,7 @@
//! ``` //! ```
//! //!
//! ### If-expressions //! ### If-expressions
//! ``` //! ```text
//! if_expr := "if" discriminator ("then" condititional | "is" simple_pattern_match | guard_block) //! if_expr := "if" discriminator ("then" condititional | "is" simple_pattern_match | guard_block)
//! discriminator := precedence_expr (operator)+ //! discriminator := precedence_expr (operator)+
//! conditional := expr_or_block else_clause //! conditional := expr_or_block else_clause
@ -126,7 +126,7 @@
//! ``` //! ```
//! //!
//! ### While expressions //! ### While expressions
//! ``` //! ```text
//! while_expr := "while" while_cond "{" (statement delimiter)* "}" //! while_expr := "while" while_cond "{" (statement delimiter)* "}"
//! while_cond := ε | expression | expression "is" pattern //TODO maybe is-expresions should be primary //! while_cond := ε | expression | expression "is" pattern //TODO maybe is-expresions should be primary
//! ``` //! ```
@ -134,7 +134,7 @@
//! //TODO this implies there must be at least one enumerator, which the parser doesn"t support right //! //TODO this implies there must be at least one enumerator, which the parser doesn"t support right
//! //this second, and maybe should fail later anyway //! //this second, and maybe should fail later anyway
//! ### For-expressions //! ### For-expressions
//! ``` //! ```text
//! for_expr := "for" (enumerator | "{" enumerators "}") for_expr_body //! for_expr := "for" (enumerator | "{" enumerators "}") for_expr_body
//! for_expr_body := "return" expression | "{" (statement delimiter)* "}" //! for_expr_body := "return" expression | "{" (statement delimiter)* "}"
//! enumerators := enumerator ("," enumerators)* //! enumerators := enumerator ("," enumerators)*
@ -642,9 +642,9 @@ impl Parser {
InvocationArgument::Ignored InvocationArgument::Ignored
}, },
Identifier(s) => { Identifier(s) => {
self.token_handler.next(); match self.token_handler.peek_kind_n(1) {
match self.token_handler.peek_kind() {
Operator(ref op) if **op == "=" => { Operator(ref op) if **op == "=" => {
self.token_handler.next();
self.token_handler.next(); self.token_handler.next();
let expr = self.expression()?; let expr = self.expression()?;
InvocationArgument::Keyword { name: s.clone(), expr } InvocationArgument::Keyword { name: s.clone(), expr }