1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::{build_config::BuildConfig, error::*, parser::Rule};

use sway_types::{ident::Ident, span::Span};

use pest::iterators::Pair;

pub(crate) fn parse_from_pair(
    pair: Pair<Rule>,
    config: Option<&BuildConfig>,
) -> CompileResult<Ident> {
    let path = config.map(|config| config.path());
    let span = {
        if pair.as_rule() != Rule::ident {
            Span {
                span: pair.into_inner().next().unwrap().as_span(),
                path,
            }
        } else {
            Span {
                span: pair.as_span(),
                path,
            }
        }
    };
    ok(Ident::new(span), Vec::new(), Vec::new())
}