Skip to content

don't expose parser and tokenizer modules #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/error-report.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rnix::parser::ParseError;
use rnix::ParseError;
use std::{env, fs};

fn main() {
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
mod macros;
pub mod ast;
mod kinds;
pub mod parser;
mod parser;
#[cfg(test)]
mod tests;
mod token_set;
pub mod tokenizer;
mod tokenizer;

use std::marker::PhantomData;

pub use self::{kinds::SyntaxKind, tokenizer::tokenize};

use ast::AstNode;
use parser::ParseError;
pub use parser::ParseError;
use rowan::GreenNode;
pub use rowan::{NodeOrToken, TextRange, TextSize, TokenAtOffset, WalkEvent};
pub(crate) use token_set::TokenSet;

use self::tokenizer::Tokenizer;
pub use tokenizer::Token;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum NixLanguage {}
Expand All @@ -45,7 +44,7 @@ pub use ast::Root;

impl Root {
pub fn parse(s: &str) -> Parse<Root> {
let (green, errors) = parser::parse(Tokenizer::new(s));
let (green, errors) = parser::parse(tokenize(s));
Parse { green, errors, _ty: PhantomData }
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ impl Eq for State<'_> {}

pub type Token<'a> = (SyntaxKind, &'a str);

/// A convenience function for tokenizing the given input
pub fn tokenize(input: &str) -> Vec<Token<'_>> {
Tokenizer::new(input).collect()
/// Tokenize the given input
pub fn tokenize(input: &str) -> impl Iterator<Item = Token<'_>> + '_ {
Tokenizer::new(input)
}

/// The tokenizer. You may want to use the `tokenize` convenience function from this module instead.
pub struct Tokenizer<'a> {
struct Tokenizer<'a> {
ctx: Vec<Context>,
state: State<'a>,
}
Expand Down