Skip to content

Commit

Permalink
Move context prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Sep 13, 2023
1 parent 79a57e3 commit d1ac4a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/file/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_comment(&mut self) {
match self.expect_next_any_of(vec!['/', '*'], "while parsing the beginning of a comment") {
match self.expect_next_any_of(vec!['/', '*'], "parsing the beginning of a comment") {
'/' => {
loop {
let c = self.next();
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<'a> WebXFileParser<'a> {
/// include "path/to/file.webx";
/// ```
fn parse_include(&mut self) -> String {
let context = "while parsing an include statement";
let context = "parsing an include statement";
self.expect_specific_str("include", 1, context);
self.expect_next_specific('"', context);
let path = self.parse_string();
Expand All @@ -241,7 +241,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_location(&mut self) -> Result<WebXScope, String> {
let context = "while parsing a location statement";
let context = "parsing a location statement";
self.expect_specific_str("location", 1, context);
self.skip_whitespace(true);
let path = self.parse_url_path();
Expand All @@ -251,7 +251,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_type_pair(&mut self) -> (String, String) {
let context = "while parsing a type pair";
let context = "parsing a type pair";
self.skip_whitespace(true);
let name = self.parse_identifier();
self.skip_whitespace(true);
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_model(&mut self) -> WebXModel {
let context = "while parsing a model statement";
let context = "parsing a model statement";
self.expect_specific_str("model", 1, context);
let name = self.read_until('{').trim().to_string();
self.expect_next_specific('{', context);
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<'a> WebXFileParser<'a> {
/// )
/// ```
fn parse_handler(&mut self) -> WebXHandler {
let context = "while parsing a handler statement";
let context = "parsing a handler statement";
self.skip_whitespace(true);
let name = self.read_until('(').trim().to_string();
self.expect_next_specific('(', context);
Expand All @@ -340,7 +340,7 @@ impl<'a> WebXFileParser<'a> {
/// (arg: string)?
/// ```
fn parse_url_path_variable(&mut self) -> String {
let context = "while parsing a URL path variable segment";
let context = "parsing a URL path variable segment";
let name = self.read_until(':').trim().to_string();
self.expect_next_specific(':', context);
let type_ = self.read_until(')').trim().to_string();
Expand All @@ -361,7 +361,7 @@ impl<'a> WebXFileParser<'a> {
/// /path/to/(arg: string)?/*
/// ```
fn parse_url_path(&mut self) -> String {
let context = "while parsing a URL path";
let context = "parsing a URL path";
let mut path = String::new();
let c = self.next_skip_whitespace(true);
if c.is_none() { exit_error_expected_but_found("endpoint path".to_string(), "EOF".to_string(), context, self.line, self.column, ERROR_SYNTAX); }
Expand Down Expand Up @@ -395,7 +395,7 @@ impl<'a> WebXFileParser<'a> {
/// User
/// ```
fn parse_body_format(&mut self) -> Option<String> {
let context = "while parsing a request body format";
let context = "parsing a request body format";
self.skip_whitespace(true);
let nc = self.peek();
if nc.is_some() && char::is_alphabetic(nc.unwrap()) {
Expand All @@ -406,7 +406,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_handler_call(&mut self) -> String {
let context = "while parsing a handler call";
let context = "parsing a handler call";
// parse "handler(arg1, arg2, ...): output"
let mut call = self.read_until(')');
call.push(self.expect_next_specific(')', context));
Expand All @@ -422,7 +422,7 @@ impl<'a> WebXFileParser<'a> {
}

fn parse_route_handlers(&mut self) -> Vec<String> {
let context = "while parsing route handlers";
let context = "parsing route handlers";
self.skip_whitespace(true);
match self.peek() {
Some('-') => {
Expand Down Expand Up @@ -480,7 +480,7 @@ impl<'a> WebXFileParser<'a> {
/// # Arguments
/// * `is_global` - Whether the scope is global or not.
fn parse_scope(&mut self, is_global: bool) -> Result<WebXScope, String> {
let context = "while parsing a scope";
let context = "parsing a scope";
let mut scope = WebXScope {
global_ts: String::new(),
includes: vec![],
Expand Down
6 changes: 3 additions & 3 deletions src/reporting/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub fn exit_error(message: String, code: i32) -> ! {
}

pub fn exit_error_unexpected(what: String, context: &str, line: usize, column: usize, code: i32) -> ! {
exit_error(format!("Unexpected {} {} at line {}, column {}", what, context, line, column), code);
exit_error(format!("Unexpected {} while {} at line {}, column {}", what, context, line, column), code);
}

pub fn exit_error_expected_but_found(expected: String, found: String, context: &str, line: usize, column: usize, code: i32) -> ! {
exit_error(format!("Expected {} but found '{}' {} at line {}, column {}", expected, found, context, line, column), code);
exit_error(format!("Expected {} but found '{}' while {} at line {}, column {}", expected, found, context, line, column), code);
}

pub fn exit_error_expected_any_of_but_found(expected: String, found: char, context: &str, line: usize, column: usize, code: i32) -> ! {
exit_error(format!("Expected any of {} but found '{}' {} at line {}, column {}", expected, found, context, line, column), code);
exit_error(format!("Expected any of {} but found '{}' while {} at line {}, column {}", expected, found, context, line, column), code);
}

pub fn exit_error_unexpected_char(what: char, context: &str, line: usize, column: usize, code: i32) -> ! {
Expand Down

0 comments on commit d1ac4a6

Please sign in to comment.