Skip to content

Commit

Permalink
Implement parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 17, 2024
1 parent 2bdf4a4 commit b59f172
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/elements/command/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,17 @@ impl SimpleCommand {
}

fn eat_word(feeder: &mut Feeder, ans: &mut SimpleCommand, core: &mut ShellCore) -> bool {
let word_len = feeder.scanner_word(core);
if word_len == 0 {
return false;
}

let word = feeder.consume(word_len);
if ans.words.len() == 0 && reserved(&word) {
let w = match Word::parse(feeder, core) {
Some(w) => w,
_ => return false,
};

if ans.words.len() == 0 && reserved(&w.text) {
return false;
}
ans.text += &word.clone();
ans.words.push(Word{ text: word });

ans.text += &w.text;
ans.words.push(w);
true
}

Expand Down
21 changes: 21 additions & 0 deletions src/elements/word.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//SPDX-FileCopyrightText: 2023 Ryuichi Ueda ryuichiueda@gmail.com
//SPDX-License-Identifier: BSD-3-Clause

use crate::{ShellCore, Feeder};

#[derive(Debug)]
pub struct Word {
pub text: String,
Expand All @@ -10,4 +12,23 @@ impl Word {
pub fn get_args(&mut self) -> Vec<String> {
vec![self.text.clone()]
}

fn new() -> Word {
Word {
text: String::new(),
}
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<Word> {
let mut ans = Word::new();
let arg_len = feeder.scanner_word(core);

if arg_len > 0 {
ans.text = feeder.consume(arg_len);
Some(ans)
}else{
None
}
}
}

0 comments on commit b59f172

Please sign in to comment.