Skip to content

Commit

Permalink
Change rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 31, 2024
1 parent 34d7620 commit 193baff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
15 changes: 9 additions & 6 deletions src/elements/subword/unquoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ impl Subword for UnquotedSubword {
}

impl UnquotedSubword {
fn new() -> UnquotedSubword {
fn new(s: &str) -> UnquotedSubword {
UnquotedSubword {
text: String::new(),
text: s.to_string(),
}
}
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<UnquotedSubword> {
let mut ans = Self::new();
if feeder.starts_with("{")
|| feeder.starts_with(",")
|| feeder.starts_with("}") {
return Some(Self::new( &feeder.consume(1) ));
}

let len = feeder.scanner_word(core);
if len == 0 {
return None;
}

ans.text = feeder.consume(len);
Some(ans)
Some( Self::new(&feeder.consume(len)) )
}
}
6 changes: 6 additions & 0 deletions src/elements/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ impl Word {
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<Word> {
if feeder.starts_with("#") {
return None;
}

let mut ans = Word::new();

while let Some(sw) = subword::parse(feeder, core) {
ans.text += &sw.get_text();
ans.subwords.push(sw);
Expand All @@ -29,6 +34,7 @@ impl Word {
if ans.text.len() == 0 {
None
}else{
//dbg!("{:?}", &ans);
Some(ans)
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/feeder/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ impl Feeder {
}

pub fn scanner_word(&mut self, core: &mut ShellCore) -> usize {
if self.remaining.starts_with("#") {
return 0;
}

let ng = match core.word_nest.last().unwrap().as_str() {
"{" => " \t\n;&|()<>},",
_ => " \t\n;&|()<>",
};
let ng = " \t\n;&|()<>{},";

let mut next_line = false;
let mut ans = 0;
Expand Down

0 comments on commit 193baff

Please sign in to comment.