aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-09-02 16:43:50 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-09-02 16:43:50 +0200
commitfd393833497aeaf0e9eb9d69509c1d04f7549201 (patch)
tree60a1327e1ab7e7d786ee637b620648e1ad7e1eda /lib/xixanta
parentf5f94d1967c18f986c6c0fe09f360044a5847970 (diff)
downloadtools.nes-fd393833497aeaf0e9eb9d69509c1d04f7549201.tar.gz
tools.nes-fd393833497aeaf0e9eb9d69509c1d04f7549201.zip
parser: Allow .include inside of .scope
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta')
-rw-r--r--lib/xixanta/src/parser.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index 04f8959..75e6cd8 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -752,13 +752,28 @@ impl Parser {
) {
// Validate that it's a top layer statement.
if self.nodes.len() > 1 {
- return Err(Error {
- line: node.value.line,
- global: false,
- message: ".include statement cannot be inside of a code block".to_string(),
- source: self.sources[self.current_source].clone(),
+ // This is not a top layer statement! Usually it would be a
+ // cause for trouble, but we actually allow this in case this is
+ // all just a bunch of `.scope` statements surrounding
+ // things. NOTE: the iteration has to go over all top nodes
+ // except the last one which is the current one.
+ let nodes = &self.nodes[..self.nodes.len() - 1];
+ if nodes.iter().any(|n| {
+ !matches!(
+ n.last().unwrap().node_type,
+ NodeType::Control(ControlType::StartScope)
+ )
+ }) {
+ // There is something else besides a '.scope' statement,
+ // this is just asking for trouble...
+ return Err(Error {
+ line: node.value.line,
+ global: false,
+ message: ".include statement cannot be inside of a code block".to_string(),
+ source: self.sources[self.current_source].clone(),
+ }
+ .into());
}
- .into());
}
// Before including all the nodes from the referenced file, add the