mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 08:55:38 +00:00
Add README, LICENSE, examples, fix draw parser lookahead
README: project overview, quick start, feature list, example table LICENSE: MIT 4 new examples covering all language features: - arrays_and_functions: arrays, while loops, inline/regular functions - state_machine: multi-state flow with on enter/exit handlers - sprites_and_palettes: inline CHR data, palette switching, scroll, cast - mmc1_banked: MMC1 mapper, bank declarations, software multiply Parser fix: draw statement keyword-arg parsing now checks for ':' lookahead before consuming an identifier, preventing it from eating the next statement as a keyword argument (e.g., `i += 1` after a draw). https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
5434dda114
commit
b8c9e41276
8 changed files with 560 additions and 44 deletions
|
|
@ -39,6 +39,10 @@ impl Parser {
|
|||
.map_or(&TokenKind::Eof, |t| &t.kind)
|
||||
}
|
||||
|
||||
fn peek_at_offset(&self, offset: usize) -> Option<&TokenKind> {
|
||||
self.tokens.get(self.pos + offset).map(|t| &t.kind)
|
||||
}
|
||||
|
||||
fn current_span(&self) -> Span {
|
||||
self.tokens.get(self.pos).map_or(Span::dummy(), |t| t.span)
|
||||
}
|
||||
|
|
@ -841,7 +845,10 @@ impl Parser {
|
|||
let mut frame = None;
|
||||
|
||||
// Parse keyword arguments: at: (x, y), frame: n
|
||||
while let TokenKind::Ident(_) = self.peek() {
|
||||
// Only consume an ident if it's followed by ':', indicating a keyword arg.
|
||||
while matches!(self.peek(), TokenKind::Ident(_))
|
||||
&& self.peek_at_offset(1) == Some(&TokenKind::Colon)
|
||||
{
|
||||
let (key, _) = self.expect_ident()?;
|
||||
self.expect(&TokenKind::Colon)?;
|
||||
match key.as_str() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue