Skip to content

Commit

Permalink
delete nom
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviRain-Su committed Oct 10, 2023
1 parent daaf02e commit 62eae62
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 95 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ anyhow = "1.0.75"
env_logger = "0.10.0"
global = "0.4.3"
thiserror = "1.0.49"
nom = "7.1.3"
once_cell = "1.18.0"
14 changes: 0 additions & 14 deletions examples/nom_example.rs

This file was deleted.

61 changes: 0 additions & 61 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
use crate::error::Error;
use crate::token::token_type::TokenType;
use crate::token::{token_type, Token};
// use nom::bytes::complete::take_until;
// use nom::bytes::complete::take_while;
// use nom::character::complete::anychar;
// use nom::character::complete::none_of;
// use nom::character::complete::{alpha1, digit1, multispace0, one_of};
// use nom::combinator::map;
// use nom::multi::many0;
// use nom::sequence::terminated;
// use nom::sequence::{delimited, preceded, tuple};
// use nom::{branch::alt, multi::many1};
// use nom::{
// bytes::complete::tag,
// character::complete::{char, space0},
// };
// use nom::{bytes::complete::take, error::ErrorKind, IResult};
use std::str;

#[cfg(test)]
Expand Down Expand Up @@ -141,52 +126,6 @@ impl<'a> Lexer<'a> {
Ok(self.input[position..self.position].to_string())
}

// fn parse_string(input: &str) -> IResult<&str, &str> {
// // TODO: (need to open in the future)
// let (input, _) = tag("\"")(input)?;
// let (input, content) = take_while(|c| c != '"')(input)?;
// let (input, _) = tag("\"")(input)?;
// Ok((input, content))
// }

// fn read_string_v1(&mut self) -> anyhow::Result<String> {
// match Lexer::parse_string(&self.input[self.position..]) {
// Ok((remaining, content)) => {
// println!("remain: {}, content: {}", remaining, content);
// // 更新position
// self.position += self.input[self.position..].len() - remaining.len();
// Ok(content.to_string())
// }
// Err(_) => Err(anyhow::anyhow!("Failed to parse string")),
// }
// }

// fn parse_token(input: &str) -> IResult<&str, Token> {
// nom::branch::alt((
// map(alpha1, |s: &str| {
// let token_type = token_type::lookup_ident(s);
// Token::from_string(token_type, s.to_string())
// }),
// map(digit1, |s: &str| {
// Token::from_string(TokenType::INT, s.to_string())
// }),
// map(one_of("+-/*<>;(),:{}[]"), |ch: char| {
// Token::from_char(token_type::lookup_char(ch), ch)
// }),
// map(
// delimited(tag("\""), take_until("\""), tag("\"")),
// |s: &str| Token::from_string(TokenType::STRING, s.to_string()),
// ),
// ))(input)
// }

// pub fn next_token_v1(&mut self) -> anyhow::Result<Token> {
// let (_, token) = Self::parse_token(&self.input[self.position..])
// .map_err(|e| anyhow::anyhow!("Failed to parse token -> {:?}", e.to_string()))?;
// self.position += token.literal().len();
// Ok(token)
// }

/// 先处理标识符和关键字。对于这两者,词法分析器需要识别当前字符是否为字母。
/// 如果是,则还需要读取标识符/关键字的剩余部分,直到遇见非字母字符为止。读取完
/// 该标识符/关键字之后,还需要判断它到底是标识符还是关键字,以便使用正确的
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused_imports)]

#[macro_use]
extern crate lazy_static;
extern crate core;
Expand Down

0 comments on commit 62eae62

Please sign in to comment.