Skip to content

Commit bdf3279

Browse files
committed
Reduce visibility of internal functions
1 parent e88e78f commit bdf3279

File tree

5 files changed

+20
-57
lines changed

5 files changed

+20
-57
lines changed

src/language/types.rs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub use crate::language::quantity::Quantity;
214214
// the validate functions all need to have start and end anchors, which seems
215215
// like it should be abstracted away.
216216

217-
pub fn validate_license(input: &str) -> Option<&str> {
217+
pub(crate) fn validate_license(input: &str) -> Option<&str> {
218218
let re = regex!(r"^[A-Za-z0-9.,\-_ \(\)\[\]]+$");
219219

220220
if re.is_match(input) {
@@ -224,7 +224,7 @@ pub fn validate_license(input: &str) -> Option<&str> {
224224
}
225225
}
226226

227-
pub fn validate_copyright(input: &str) -> Option<&str> {
227+
pub(crate) fn validate_copyright(input: &str) -> Option<&str> {
228228
let re = regex!(r"^[A-Za-z0-9.,\-_ \(\)\[\]]+$");
229229

230230
if re.is_match(input) {
@@ -234,7 +234,7 @@ pub fn validate_copyright(input: &str) -> Option<&str> {
234234
}
235235
}
236236

237-
pub fn validate_template(input: &str) -> Option<&str> {
237+
pub(crate) fn validate_template(input: &str) -> Option<&str> {
238238
let re = regex!(r"^[A-Za-z0-9.,\-]+$");
239239

240240
if re.is_match(input) {
@@ -244,7 +244,7 @@ pub fn validate_template(input: &str) -> Option<&str> {
244244
}
245245
}
246246

247-
pub fn validate_identifier(input: &str) -> Option<Identifier<'_>> {
247+
pub(crate) fn validate_identifier(input: &str) -> Option<Identifier<'_>> {
248248
if input.len() == 0 {
249249
return None;
250250
}
@@ -257,7 +257,7 @@ pub fn validate_identifier(input: &str) -> Option<Identifier<'_>> {
257257
}
258258
}
259259

260-
pub fn validate_forma(input: &str) -> Option<Forma<'_>> {
260+
pub(crate) fn validate_forma(input: &str) -> Option<Forma<'_>> {
261261
if input.len() == 0 {
262262
return None;
263263
}
@@ -294,7 +294,7 @@ fn parse_tuple(input: &str) -> Option<Vec<Forma<'_>>> {
294294
}
295295

296296
/// This one copes with (and discards) any internal whitespace encountered.
297-
pub fn validate_genus(input: &str) -> Option<Genus<'_>> {
297+
pub(crate) fn validate_genus(input: &str) -> Option<Genus<'_>> {
298298
let first = input
299299
.chars()
300300
.next()
@@ -371,33 +371,6 @@ pub fn validate_response(input: &str) -> Option<Response<'_>> {
371371
Some(Response { value, condition })
372372
}
373373

374-
fn _validate_decimal(_input: &str) -> Option<Numeric<'_>> {
375-
// Test the regex macro availability within types.rs
376-
let _decimal_regex = regex!(r"^\s*-?[0-9]+\.[0-9]+\s*$");
377-
// For now, just return None since we removed Decimal variant
378-
None
379-
}
380-
381-
pub fn validate_numeric(input: &str) -> Option<Numeric<'_>> {
382-
if input.is_empty() {
383-
return None;
384-
}
385-
386-
let input = input.trim_ascii();
387-
388-
// Try to parse as a simple Integral first
389-
if let Ok(amount) = input.parse::<i64>() {
390-
return Some(Numeric::Integral(amount));
391-
}
392-
393-
// Try to parse as a Quantity (scientific notation with units)
394-
if let Some(quantity) = parse_quantity(input) {
395-
return Some(Numeric::Scientific(quantity));
396-
}
397-
398-
None
399-
}
400-
401374
#[cfg(test)]
402375
mod check {
403376
use super::*;
@@ -582,18 +555,6 @@ mod check {
582555
t1
583556
}
584557

585-
#[test]
586-
fn numeric_rules() {
587-
// Test simple integers
588-
assert_eq!(validate_numeric("42"), Some(Numeric::Integral(42)));
589-
assert_eq!(validate_numeric("0"), Some(Numeric::Integral(0)));
590-
assert_eq!(validate_numeric("-123"), Some(Numeric::Integral(-123)));
591-
assert_eq!(
592-
validate_numeric("9223372036854775807"),
593-
Some(Numeric::Integral(9223372036854775807))
594-
);
595-
}
596-
597558
#[test]
598559
fn ast_construction() {
599560
let t1 = Metadata {

src/parsing/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use std::path::Path;
44
use tracing::debug;
55

66
use crate::language::{Document, LoadingError, Technique};
7-
use crate::parsing::parser::ParsingError;
87

9-
pub mod parser;
8+
mod parser;
109
mod scope;
1110

11+
// Export the actual public API
12+
pub use parser::{parse_with_recovery, Parser, ParsingError};
13+
1214
/// Read a file and return an owned String. We pass that ownership back to the
1315
/// main function so that the Technique object created by parse() below can
1416
/// have the same lifetime.

src/parsing/parser.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub struct Parser<'i> {
136136
}
137137

138138
impl<'i> Parser<'i> {
139-
pub fn new() -> Parser<'i> {
139+
fn new() -> Parser<'i> {
140140
Parser {
141141
filename: Path::new("-"),
142142
original: "",
@@ -146,10 +146,10 @@ impl<'i> Parser<'i> {
146146
}
147147
}
148148

149-
pub fn filename(&mut self, filename: &'i Path) {
149+
fn filename(&mut self, filename: &'i Path) {
150150
self.filename = filename;
151151
}
152-
pub fn initialize(&mut self, content: &'i str) {
152+
fn initialize(&mut self, content: &'i str) {
153153
self.original = content;
154154
self.source = content;
155155
self.offset = 0;
@@ -732,7 +732,7 @@ impl<'i> Parser<'i> {
732732
})
733733
}
734734

735-
pub fn read_technique_header(&mut self) -> Result<Metadata<'i>, ParsingError> {
735+
fn read_technique_header(&mut self) -> Result<Metadata<'i>, ParsingError> {
736736
// Process magic line
737737
let version = if is_magic_line(self.source) {
738738
let result = self.read_magic_line()?;
@@ -907,7 +907,7 @@ impl<'i> Parser<'i> {
907907
}
908908

909909
/// Parse a procedure with error recovery - collects multiple errors instead of stopping at the first one
910-
pub fn read_procedure(&mut self) -> Result<Procedure<'i>, ParsingError> {
910+
fn read_procedure(&mut self) -> Result<Procedure<'i>, ParsingError> {
911911
// Find the procedure block boundaries
912912
let mut i = 0;
913913
let mut begun = false;
@@ -1821,7 +1821,7 @@ impl<'i> Parser<'i> {
18211821
}
18221822

18231823
/// Parse top-level ordered step
1824-
pub fn read_step_dependent(&mut self) -> Result<Scope<'i>, ParsingError> {
1824+
fn read_step_dependent(&mut self) -> Result<Scope<'i>, ParsingError> {
18251825
self.take_block_lines(is_step_dependent, is_step_dependent, |outer| {
18261826
outer.trim_whitespace();
18271827

@@ -1860,7 +1860,7 @@ impl<'i> Parser<'i> {
18601860
}
18611861

18621862
/// Parse a top-level concurrent step
1863-
pub fn read_step_parallel(&mut self) -> Result<Scope<'i>, ParsingError> {
1863+
fn read_step_parallel(&mut self) -> Result<Scope<'i>, ParsingError> {
18641864
self.take_block_lines(is_step_parallel, is_step_parallel, |outer| {
18651865
outer.trim_whitespace();
18661866

@@ -1961,7 +1961,7 @@ impl<'i> Parser<'i> {
19611961
)
19621962
}
19631963

1964-
pub fn read_descriptive(&mut self) -> Result<Vec<Paragraph<'i>>, ParsingError> {
1964+
fn read_descriptive(&mut self) -> Result<Vec<Paragraph<'i>>, ParsingError> {
19651965
self.take_block_lines(
19661966
|_| true,
19671967
|line| {

src/problem/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::messages::generate_error_message;
22
use owo_colors::OwoColorize;
33
use std::path::Path;
4-
use technique::{formatting::Render, language::LoadingError, parsing::parser::ParsingError};
4+
use technique::{formatting::Render, language::LoadingError, parsing::ParsingError};
55

66
/// Format a parsing error with full details including source code context
77
pub fn full_parsing_error<'i>(

src/problem/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::problem::Present;
2-
use technique::{formatting::Render, language::*, parsing::parser::ParsingError};
2+
use technique::{formatting::Render, language::*, parsing::ParsingError};
33

44
/// Generate problem and detail messages for parsing errors using AST construction
55
pub fn generate_error_message<'i>(error: &ParsingError, renderer: &dyn Render) -> (String, String) {

0 commit comments

Comments
 (0)