-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embed declaration for foreign language integration
- Loading branch information
Showing
19 changed files
with
16,121 additions
and
15,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::analyzer_error::AnalyzerError; | ||
use veryl_parser::veryl_grammar_trait::*; | ||
use veryl_parser::veryl_walker::{Handler, HandlerPoint}; | ||
use veryl_parser::ParolError; | ||
|
||
pub struct CheckEmbed<'a> { | ||
pub errors: Vec<AnalyzerError>, | ||
text: &'a str, | ||
point: HandlerPoint, | ||
} | ||
|
||
impl<'a> CheckEmbed<'a> { | ||
pub fn new(text: &'a str) -> Self { | ||
Self { | ||
errors: Vec::new(), | ||
text, | ||
point: HandlerPoint::Before, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Handler for CheckEmbed<'a> { | ||
fn set_point(&mut self, p: HandlerPoint) { | ||
self.point = p; | ||
} | ||
} | ||
|
||
impl<'a> VerylGrammarTrait for CheckEmbed<'a> { | ||
fn embed_declaration(&mut self, arg: &EmbedDeclaration) -> Result<(), ParolError> { | ||
if let HandlerPoint::Before = self.point { | ||
let way = arg.identifier.identifier_token.to_string(); | ||
let lang = arg.identifier0.identifier_token.to_string(); | ||
|
||
if !EMBED_WAY.contains(&way.as_str()) { | ||
self.errors.push(AnalyzerError::unknown_embed_way( | ||
&way, | ||
self.text, | ||
&arg.identifier.identifier_token.token, | ||
)); | ||
} | ||
|
||
if !EMBED_LANG.contains(&lang.as_str()) { | ||
self.errors.push(AnalyzerError::unknown_embed_lang( | ||
&lang, | ||
self.text, | ||
&arg.identifier0.identifier_token.token, | ||
)); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
const EMBED_WAY: [&str; 1] = ["inline"]; | ||
const EMBED_LANG: [&str; 1] = ["sv"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ pub const KEYWORDS: &[&str] = &[ | |
"case", | ||
"default", | ||
"else", | ||
"embed", | ||
"enum", | ||
"export", | ||
"f32", | ||
|
Oops, something went wrong.