11/// An error that can occur during parsing.
22#[ derive( Copy , Clone ) ]
33pub ( crate ) struct ParseError {
4- pub remaining : usize ,
5- pub cause : ParseErrorCause ,
4+ pub ( crate ) remaining : usize ,
5+ pub ( crate ) cause : ParseErrorCause ,
66}
77
88impl ParseError {
99 /// Given the original string, returns the 1-based position
1010 /// of the error in characters.
1111 /// If an incorrect string was given, the function may return 0.
12- pub fn calculate_position ( & self , original : & str ) -> Option < usize > {
12+ pub ( crate ) fn calculate_position ( & self , original : & str ) -> Option < usize > {
1313 calculate_position ( original, self . remaining )
1414 }
1515
1616 /// Returns the error cause.
17- pub fn get_cause ( & self ) -> ParseErrorCause {
17+ pub ( crate ) fn get_cause ( & self ) -> ParseErrorCause {
1818 self . cause
1919 }
2020}
@@ -49,13 +49,13 @@ pub(crate) struct ParserState<'s> {
4949
5050impl < ' s > ParserState < ' s > {
5151 /// Creates a new parser from given input string.
52- pub fn new ( s : & ' s str ) -> Self {
52+ pub ( crate ) fn new ( s : & ' s str ) -> Self {
5353 Self { s }
5454 }
5555
5656 /// Applies given parsing function until it returns false
5757 /// and returns the final parser state.
58- pub fn parse_while (
58+ pub ( crate ) fn parse_while (
5959 self ,
6060 mut parser : impl FnMut ( Self ) -> ParseResult < ( bool , Self ) > ,
6161 ) -> ParseResult < Self > {
@@ -72,39 +72,39 @@ impl<'s> ParserState<'s> {
7272 /// If the input string contains given string at the beginning,
7373 /// returns a new parser state with given string skipped.
7474 /// Otherwise, returns an error.
75- pub fn accept ( self , part : & ' static str ) -> ParseResult < Self > {
75+ pub ( crate ) fn accept ( self , part : & ' static str ) -> ParseResult < Self > {
7676 match self . s . strip_prefix ( part) {
7777 Some ( s) => Ok ( Self { s } ) ,
7878 None => Err ( self . error ( ParseErrorCause :: Expected ( part) ) ) ,
7979 }
8080 }
8181
8282 /// Returns new parser state with whitespace skipped from the beginning.
83- pub fn skip_white ( self ) -> Self {
83+ pub ( crate ) fn skip_white ( self ) -> Self {
8484 let ( _, me) = self . take_while ( char:: is_whitespace) ;
8585 me
8686 }
8787
8888 /// Skips characters from the beginning while they satisfy given predicate
8989 /// and returns new parser state which
90- pub fn take_while ( self , mut pred : impl FnMut ( char ) -> bool ) -> ( & ' s str , Self ) {
90+ pub ( crate ) fn take_while ( self , mut pred : impl FnMut ( char ) -> bool ) -> ( & ' s str , Self ) {
9191 let idx = self . s . find ( move |c| !pred ( c) ) . unwrap_or ( self . s . len ( ) ) ;
9292 let new = Self { s : & self . s [ idx..] } ;
9393 ( & self . s [ ..idx] , new)
9494 }
9595
9696 /// Returns the number of remaining bytes to parse.
97- pub fn get_remaining ( self ) -> usize {
97+ pub ( crate ) fn get_remaining ( self ) -> usize {
9898 self . s . len ( )
9999 }
100100
101101 /// Returns true if the input string was parsed completely.
102- pub fn is_at_eof ( self ) -> bool {
102+ pub ( crate ) fn is_at_eof ( self ) -> bool {
103103 self . s . is_empty ( )
104104 }
105105
106106 /// Returns an error with given cause, associated with given position.
107- pub fn error ( self , cause : ParseErrorCause ) -> ParseError {
107+ pub ( crate ) fn error ( self , cause : ParseErrorCause ) -> ParseError {
108108 ParseError {
109109 remaining : self . get_remaining ( ) ,
110110 cause,
@@ -114,7 +114,7 @@ impl<'s> ParserState<'s> {
114114 /// Given the original string, returns the 1-based position
115115 /// of the error in characters.
116116 /// If an incorrect string was given, the function may return None.
117- pub fn calculate_position ( self , original : & str ) -> Option < usize > {
117+ pub ( crate ) fn calculate_position ( self , original : & str ) -> Option < usize > {
118118 calculate_position ( original, self . get_remaining ( ) )
119119 }
120120}
0 commit comments