pub fn parse_from_location(
        &mut self,
        buffer: &'parser str,
        starting_line_number: usize,
        starting_column_number: usize,
    ) -> Result<Array, Error> {
        self.remaining = buffer;
        self.current_line = &self.remaining;

        assert!(starting_line_number > 0, "document line numbers are 1-based");
        self.next_line_number = starting_line_number;
        self.next_column_number = starting_column_number;

        self.next_line = self.current_line;
        self.line_number = self.next_line_number - 1;
        self.column_number = self.next_column_number - 1;
        self.scope_stack = vec![Rc::new(RefCell::new(Array::new(vec![])))];

        let mut next_token = Capturer::new(&NEXT_TOKEN);
        let mut single_quoted = Capturer::new(&SINGLE_QUOTED);
        let mut double_quoted = Capturer::new(&DOUBLE_QUOTED);
        let mut line_comment = Capturer::new(&LINE_COMMENT);
        let mut block_comment = Capturer::new(&BLOCK_COMMENT);

        // Blocks of adjacent line comments should be kept together as a "line comment block", but
        // adjacent line comment blocks separated by one or more newlines must be maintained as
        // separate blocks.
        //
        // These booleans, along with `reset_line_comment_break_check`, update state information as
        // line comments and blank lines are parsed.
        let mut just_captured_line_comment = false;
        let mut pending_blank_line = false;
        let mut pending_new_line_comment_block = false;

        while self.remaining.len() > 0 {
            // See comment above regarding "line comment blocks".
            let mut reset_line_comment_break_check = true;

            if self.capture(&mut next_token) {
                // Since this has to be done as an if-else-if-... check the most common
                // occurrences first.
                if let Some(_) = next_token.captured(*WHITESPACE) {
                    reset_line_comment_break_check = false;
                    Ok(()) // ignore all whitespace not in a string or comment
                } else if let Some(_) = next_token.captured(*NEWLINE) {
                    reset_line_comment_break_check = false;
                    if just_captured_line_comment {
                        if pending_blank_line {
                            pending_new_line_comment_block = true;
                            pending_blank_line = false;
                        } else if !pending_new_line_comment_block {
                            pending_blank_line = true;
                        }
                    }
                    self.on_newline()
                } else if let Some(_) = next_token.captured(*COMMA) {
                    self.end_value()
                } else if let Some(brace) = next_token.captured(*BRACE) {
                    self.on_brace(&brace)
                } else if let Some(non_string_primitive) =
                    next_token.captured(*NON_STRING_PRIMITIVE)
                {
                    self.add_non_string_primitive(&non_string_primitive)
                } else if let Some(quote) = next_token.captured(*OPEN_QUOTE) {
                    let quoted_string = if quote == "'" {
                        self.consume(&mut single_quoted)
                    } else {
                        self.consume(&mut double_quoted)
                    };
                    self.add_quoted_string(&quote, quoted_string)
                } else if let Some(unquoted_property_name) =
                    next_token.captured(*UNQUOTED_PROPERTY_NAME_AND_COLON)
                {
                    self.set_pending_property(unquoted_property_name)
                } else if let Some(_line_comment_start) = next_token.captured(*LINE_COMMENT_SLASHES)
                {
                    reset_line_comment_break_check = false;
                    pending_blank_line = false;
                    let line_comment = self.consume(&mut line_comment);
                    if self.add_line_comment(line_comment, pending_new_line_comment_block)? {
                        // standalone line comment
                        just_captured_line_comment = true;
                        pending_new_line_comment_block = false;
                    } // else it was an end-of-line comment
                    Ok(())
                } else if let Some(_block_comment_start) = next_token.captured(*OPEN_BLOCK_COMMENT)
                {
                    let block_comment = self.consume(&mut block_comment);
                    self.add_block_comment(block_comment)
                } else {
                    Err(Error::internal(
                        self.location(),
                        format!(
                            "NEXT_TOKEN matched an unexpected capture group: {}",
                            next_token.overall_match().unwrap_or("")
                        ),
                    ))
                }
            } else {
                Err(self.error("Unexpected token"))
            }?;

            if reset_line_comment_break_check {
                just_captured_line_comment = false;
                pending_blank_line = false;
                pending_new_line_comment_block = false;
            }
        }
        self.remaining = "";
        self.close_document()?;

        match Rc::try_unwrap(self.scope_stack.pop().unwrap())
            .map_err(|_| Error::internal(None, "Rc<> for document array could not be unwrapped."))?
            .into_inner()
        {
            Value::Array { val, .. } => Ok(val),
            unexpected => Err(Error::internal(
                self.location(),
                format!("Final scope should be an Array, but scope was {:?}", unexpected),
            )),
        }
    }
/// Parse the given document string as a JSON5 document containing Array
/// elements (with implicit outer braces), and use the given 1-based line
/// and column numbers when referring to document locations.
Parse the given document string as a JSON5 document containing Array
elements (with implicit outer braces), and use the given 1-based line
and column numbers when referring to document locations.
Parse the given document string as a JSON5 document containing Array elements ( with implicit outer braces ) and use the given 1 - based line and column numbers when referring to document locations .
pub fn parse_from_location(
        &mut self,
        buffer: &'parser str,
        starting_line_number: usize,
        starting_column_number: usize,
    ) -> Result<Array, Error> {
        self.remaining = buffer;
        self.current_line = &self.remaining;
        assert!(starting_line_number > 0, "document line numbers are 1-based");
        self.next_line_number = starting_line_number;
        self.next_column_number = starting_column_number;
        self.next_line = self.current_line;
        self.line_number = self.next_line_number - 1;
        self.column_number = self.next_column_number - 1;
        self.scope_stack = vec![Rc::new(RefCell::new(Array::new(vec![])))];
        let mut next_token = Capturer::new(&NEXT_TOKEN);
        let mut single_quoted = Capturer::new(&SINGLE_QUOTED);
        let mut double_quoted = Capturer::new(&DOUBLE_QUOTED);
        let mut line_comment = Capturer::new(&LINE_COMMENT);
        let mut block_comment = Capturer::new(&BLOCK_COMMENT);
        // Blocks of adjacent line comments should be kept together as a "line comment block", but
        // adjacent line comment blocks separated by one or more newlines must be maintained as
        // separate blocks.
        //
        // These booleans, along with `reset_line_comment_break_check`, update state information as
        // line comments and blank lines are parsed.
        let mut just_captured_line_comment = false;
        let mut pending_blank_line = false;
        let mut pending_new_line_comment_block = false;
        while self.remaining.len() > 0 {
            // See comment above regarding "line comment blocks".
            let mut reset_line_comment_break_check = true;
            if self.capture(&mut next_token) {
                // Since this has to be done as an if-else-if-... check the most common
                // occurrences first.
                if let Some(_) = next_token.captured(*WHITESPACE) {
                    reset_line_comment_break_check = false;
                    Ok(()) // ignore all whitespace not in a string or comment
                } else if let Some(_) = next_token.captured(*NEWLINE) {
                    reset_line_comment_break_check = false;
                    if just_captured_line_comment {
                        if pending_blank_line {
                            pending_new_line_comment_block = true;
                            pending_blank_line = false;
                        } else if !pending_new_line_comment_block {
                            pending_blank_line = true;
                        }
                    }
                    self.on_newline()
                } else if let Some(_) = next_token.captured(*COMMA) {
                    self.end_value()
                } else if let Some(brace) = next_token.captured(*BRACE) {
                    self.on_brace(&brace)
                } else if let Some(non_string_primitive) =
                    next_token.captured(*NON_STRING_PRIMITIVE)
                {
                    self.add_non_string_primitive(&non_string_primitive)
                } else if let Some(quote) = next_token.captured(*OPEN_QUOTE) {
                    let quoted_string = if quote == "'" {
                        self.consume(&mut single_quoted)
                    } else {
                        self.consume(&mut double_quoted)
                    };
                    self.add_quoted_string(&quote, quoted_string)
                } else if let Some(unquoted_property_name) =
                    next_token.captured(*UNQUOTED_PROPERTY_NAME_AND_COLON)
                {
                    self.set_pending_property(unquoted_property_name)
                } else if let Some(_line_comment_start) = next_token.captured(*LINE_COMMENT_SLASHES)
                {
                    reset_line_comment_break_check = false;
                    pending_blank_line = false;
                    let line_comment = self.consume(&mut line_comment);
                    if self.add_line_comment(line_comment, pending_new_line_comment_block)? {
                        // standalone line comment
                        just_captured_line_comment = true;
                        pending_new_line_comment_block = false;
                    } // else it was an end-of-line comment
                    Ok(())
                } else if let Some(_block_comment_start) = next_token.captured(*OPEN_BLOCK_COMMENT)
                {
                    let block_comment = self.consume(&mut block_comment);
                    self.add_block_comment(block_comment)
                } else {
                    Err(Error::internal(
                        self.location(),
                        format!(
                            "NEXT_TOKEN matched an unexpected capture group: {}",
                            next_token.overall_match().unwrap_or("")
                        ),
                    ))
                }
            } else {
                Err(self.error("Unexpected token"))
            }?;
            if reset_line_comment_break_check {
                just_captured_line_comment = false;
                pending_blank_line = false;
                pending_new_line_comment_block = false;
            }
        }
        self.remaining = "";
        self.close_document()?;
        match Rc::try_unwrap(self.scope_stack.pop().unwrap())
            .map_err(|_| Error::internal(None, "Rc<> for document array could not be unwrapped."))?
            .into_inner()
        {
            Value::Array { val, .. } => Ok(val),
            unexpected => Err(Error::internal(
                self.location(),
                format!("Final scope should be an Array, but scope was {:?}", unexpected),
            )),
        }
    }
pub fn parse_from_location ( & mut self , buffer : & ' parser str , starting_line_number : usize , starting_column_number : usize , ) -> Result < Array , Error > { self . remaining = buffer ; self . current_line = & self . remaining ; assert ! ( starting_line_number 0 " " ) ; self . next_line_number = starting_line_number ; self . next_column_number = starting_column_number ; self . next_line = self . current_line ; self . line_number = self . next_line_number - 1 ; self . column_number = self . next_column_number - 1 ; self . scope_stack = vec ! [ Rc new ( RefCell new ( Array new ( vec [ ] ) ) ) ] ; let mut next_token = Capturer :: new ( & NEXT_TOKEN ) ; let mut single_quoted = Capturer :: new ( & SINGLE_QUOTED ) ; let mut double_quoted = Capturer :: new ( & DOUBLE_QUOTED ) ; let mut line_comment = Capturer :: new ( & LINE_COMMENT ) ; let mut block_comment = Capturer :: new ( & BLOCK_COMMENT ) ; // Blocks of adjacent line comments should be kept together as a "line comment block", but // adjacent line comment blocks separated by one or more newlines must be maintained as // separate blocks. // // These booleans, along with `reset_line_comment_break_check`, update state information as // line comments and blank lines are parsed. let mut just_captured_line_comment = false ; let mut pending_blank_line = false ; let mut pending_new_line_comment_block = false ; while self . remaining . len ( ) > 0 { // See comment above regarding "line comment blocks". let mut reset_line_comment_break_check = true ; if self . capture ( & mut next_token ) { // Since this has to be done as an if-else-if-... check the most common // occurrences first. if let Some ( _ ) = next_token . captured ( * WHITESPACE ) { reset_line_comment_break_check = false ; Ok ( ( ) ) // ignore all whitespace not in a string or comment } else if let Some ( _ ) = next_token . captured ( * NEWLINE ) { reset_line_comment_break_check = false ; if just_captured_line_comment { if pending_blank_line { pending_new_line_comment_block = true ; pending_blank_line = false ; } else if ! pending_new_line_comment_block { pending_blank_line = true ; } } self . on_newline ( ) } else if let Some ( _ ) = next_token . captured ( * COMMA ) { self . end_value ( ) } else if let Some ( brace ) = next_token . captured ( * BRACE ) { self . on_brace ( & brace ) } else if let Some ( non_string_primitive ) = next_token . captured ( * NON_STRING_PRIMITIVE ) { self . add_non_string_primitive ( & non_string_primitive ) } else if let Some ( quote ) = next_token . captured ( * OPEN_QUOTE ) { let quoted_string = if quote == " " { self . consume ( & mut single_quoted ) } else { self . consume ( & mut double_quoted ) } ; self . add_quoted_string ( & quote , quoted_string ) } else if let Some ( unquoted_property_name ) = next_token . captured ( * UNQUOTED_PROPERTY_NAME_AND_COLON ) { self . set_pending_property ( unquoted_property_name ) } else if let Some ( _line_comment_start ) = next_token . captured ( * LINE_COMMENT_SLASHES ) { reset_line_comment_break_check = false ; pending_blank_line = false ; let line_comment = self . consume ( & mut line_comment ) ; if self . add_line_comment ( line_comment , pending_new_line_comment_block ) ? { // standalone line comment just_captured_line_comment = true ; pending_new_line_comment_block = false ; } // else it was an end-of-line comment Ok ( ( ) ) } else if let Some ( _block_comment_start ) = next_token . captured ( * OPEN_BLOCK_COMMENT ) { let block_comment = self . consume ( & mut block_comment ) ; self . add_block_comment ( block_comment ) } else { Err ( Error :: internal ( self . location ( ) , format ! ( " " next_token overall_match ( ) unwrap_or ( " " ) ) , ) ) } } else { Err ( self . error ( " " ) ) } ? ; if reset_line_comment_break_check { just_captured_line_comment = false ; pending_blank_line = false ; pending_new_line_comment_block = false ; } } self . remaining = " " ; self . close_document ( ) ? ; match Rc :: try_unwrap ( self . scope_stack . pop ( ) . unwrap ( ) ) . map_err ( | _ | Error :: internal ( None , " " ) ) ? . into_inner ( ) { Value :: Array { val , .. } => Ok ( val ) , unexpected => Err ( Error :: internal ( self . location ( ) , format ! ( " " unexpected ) , ) ) , } }
Parse the given document string as a JSON5 document containing Array
elements (with implicit outer braces), and use the given 1-based line
and column numbers when referring to document locations.
Parse the given document string as a JSON5 document containing Array elements ( with implicit outer braces ) and use the given 1 - based line and column numbers when referring to document locations .
&mut self
buffer
&'parser str
starting_line_number
usize
starting_column_number
usize
&mut self
buffer
&'parser str
starting_line_number
usize
starting_column_number
usize