add: for sample, fix bugs, and make test harness

This commit is contained in:
2026-03-12 22:39:30 -07:00
parent 944326f114
commit 6c4118c489
11 changed files with 311 additions and 22 deletions

View File

@@ -1105,12 +1105,11 @@ impl Parser {
fn parse_paren_ident(&mut self) -> Option<String> {
if self.peek() != &Token::LParen { return None; }
self.advance(); // (
let name = if let Token::Identifier(s) = self.peek().clone() {
self.advance();
Some(s)
} else {
None
};
// Use try_parse_ident_or_name so that names which collide with keywords
// (e.g. `For` in `Ctl-Opt Main(For)`) are accepted. Lowercase the
// result so it matches how procedure names are stored by token_as_name /
// expect_name (which always return lowercase strings for keyword tokens).
let name = self.try_parse_ident_or_name().map(|s| s.to_lowercase());
self.eat(&Token::RParen);
name
}
@@ -2500,7 +2499,7 @@ impl Parser {
fn expect_ident(&mut self) -> Result<String, LowerError> {
match self.advance() {
Token::Identifier(s) => Ok(s),
Token::Identifier(s) => Ok(s.to_lowercase()),
tok => Err(LowerError::new(format!("expected identifier, got {:?}", tok))),
}
}
@@ -2572,7 +2571,7 @@ impl Parser {
/// lowercase or mixed-case spelling that the source would have used.
fn token_as_name(tok: &Token) -> Option<String> {
match tok {
Token::Identifier(s) => Some(s.clone()),
Token::Identifier(s) => Some(s.to_lowercase()),
// Statement / declaration keywords that are commonly used as names.
Token::KwMain => Some("main".into()),
@@ -2814,7 +2813,7 @@ mod tests {
fn lower_dcl_c() {
let p = lower_ok("DCL-C MAX_SIZE CONST(100);");
if let Declaration::Constant(c) = &p.declarations[0] {
assert_eq!(c.name, "MAX_SIZE");
assert_eq!(c.name, "max_size");
}
}
@@ -2840,7 +2839,7 @@ mod tests {
#[test]
fn lower_hello_rpg() {
let hello = include_str!("../hello.rpg");
let hello = include_str!("../samples/hello.rpg");
let p = lower_ok(hello);
assert!(!p.procedures.is_empty(), "should have at least one procedure");
let proc = p.procedures.iter().find(|p| p.name == "main").expect("main proc");