(&mut self, meta: &mut ParserMetadata)
| 51 | } |
| 52 | |
| 53 | fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult { |
| 54 | while let Ok(flag) = token_by(meta, |val| val.starts_with("#[")) { |
| 55 | self.flags |
| 56 | .insert(get_ccflag_by_name(&flag[2..flag.len() - 1])); |
| 57 | } |
| 58 | |
| 59 | if token(meta, "pub").is_ok() { |
| 60 | self.is_public = true; |
| 61 | } |
| 62 | |
| 63 | let keyword = token_by(meta, |word| ["let", "const"].contains(&word.as_str()))?; |
| 64 | self.is_const = keyword == "const"; |
| 65 | self.tok = meta.get_current_token(); |
| 66 | |
| 67 | if self.is_public && !self.is_const && !self.flags.contains(&CCFlags::AllowPublicMutable) { |
| 68 | let flag = get_ccflag_name(CCFlags::AllowPublicMutable); |
| 69 | return error!(meta, self.tok.clone() => { |
| 70 | message: "Public variables must be constants", |
| 71 | comment: format!("Mutable public variables create shared global state.\nUse 'pub const' or add '#[{flag}]' to allow this.") |
| 72 | }); |
| 73 | } |
| 74 | self.name = variable(meta, variable_name_extensions())?; |
| 75 | if let Err(err) = token(meta, "=") { |
| 76 | return error_pos!( |
| 77 | meta, |
| 78 | err.unwrap_quiet(), |
| 79 | format!("Expected '=' after variable name '{}'", self.name) |
| 80 | ); |
| 81 | } |
| 82 | syntax(meta, &mut *self.expr)?; |
| 83 | self.is_fun_ctx = meta.context.is_fun_ctx; |
| 84 | Ok(()) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl TypeCheckModule for VariableInit { |
nothing calls this directly
no test coverage detected