forked from MightyPork/crsn
add stdio module
This commit is contained in:
@@ -85,9 +85,24 @@ pub fn parse_data_disp(tok: Sexp, pcx: &ParserContext) -> Result<DataDisp, CrsnE
|
||||
|
||||
if s.starts_with('\'') && s.ends_with('\'') {
|
||||
if s.chars().count() == 3 {
|
||||
return Ok(DataDisp::Immediate(s.chars().nth(1).unwrap() as u64));
|
||||
let ch = s.chars().nth(1).unwrap();
|
||||
if ch == '\'' {
|
||||
return Err(CrsnError::Parse("Use '\\'' for apos".into(), pos));
|
||||
}
|
||||
return Ok(DataDisp::Immediate(ch as u64));
|
||||
} else if s.chars().count() == 4 && s.chars().nth(1).unwrap() == '\\' {
|
||||
return Ok(DataDisp::Immediate(s.chars().nth(2).unwrap() as u64));
|
||||
let ch = s.chars().nth(2).unwrap();
|
||||
let ch = match ch {
|
||||
'\\' => '\\',
|
||||
'n' => '\n',
|
||||
'r' => '\r',
|
||||
't' => '\t',
|
||||
'\'' => '\'',
|
||||
_ => {
|
||||
return Err(CrsnError::Parse(format!("Unknown escape sequence: {}", s).into(), pos));
|
||||
}
|
||||
};
|
||||
return Ok(DataDisp::Immediate(ch as u64));
|
||||
} else {
|
||||
return Err(CrsnError::Parse(format!("Invalid character literal synax {}", s).into(), pos));
|
||||
}
|
||||
@@ -96,7 +111,7 @@ pub fn parse_data_disp(tok: Sexp, pcx: &ParserContext) -> Result<DataDisp, CrsnE
|
||||
if let Some(reference) = s.strip_prefix('@') {
|
||||
/* extension constants (pre-defined handles) */
|
||||
for p in pcx.parsers {
|
||||
if let Some(val) = p.get_constant_value(&s) {
|
||||
if let Some(val) = p.get_constant_value(reference) {
|
||||
return Ok(DataDisp::ImmObject(val));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user