y_lang/ast/
inline_asm.rs

1use pest::iterators::Pair;
2
3use super::{Position, Rule};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct InlineAssembly<T> {
7    pub statements: Vec<String>,
8    pub position: Position,
9    pub info: T,
10}
11
12impl InlineAssembly<()> {
13    pub fn from_pair(pair: Pair<Rule>, file: &str) -> InlineAssembly<()> {
14        let (line, col) = pair.line_col();
15
16        let mut inner = pair.into_inner();
17        let raw_assembly = inner
18            .next()
19            .unwrap_or_else(|| panic!("Expected content in inline assembly"))
20            .as_str();
21
22        let assembly_statements = raw_assembly
23            .lines()
24            .map(|line| line.trim_matches(' ').to_owned())
25            .collect::<Vec<_>>();
26
27        InlineAssembly {
28            statements: assembly_statements,
29            position: (file.to_owned(), line, col),
30            info: (),
31        }
32    }
33}
34
35impl<T> InlineAssembly<T>
36where
37    T: Clone,
38{
39    pub fn info(&self) -> T {
40        self.info.clone()
41    }
42}