SourceLocation

Struct SourceLocation 

Source
pub struct SourceLocation(/* private fields */);

Implementations§

Source§

impl SourceLocation

Source

pub fn new(line: usize, col: usize) -> SourceLocation

Source

pub fn line(&self) -> usize

Source

pub fn col(&self) -> usize

Examples found in repository?
examples/dumps_ast.rs (line 195)
188    fn format_output<T>(&self, ast: &AstNode<T>, depth: usize) {
189        let spacing: String = std::iter::repeat(' ').take(depth).collect();
190
191        println!(
192            "{} {} -- '{}'::{},{}",
193            spacing,
194            std::any::type_name::<T>().split("::").last().unwrap(),
195            &self.source.to_string()[ast.start().col()..ast.end().col()],
196            ast.start().col(),
197            ast.end().col()
198        );
199    }
More examples
Hide additional examples
examples/explain.rs (line 66)
37fn main() {
38    let args: Vec<_> = std::env::args().collect();
39
40    if args.len() < 2 {
41        eprintln!("Usage: {} <prog> [bindings]", args[0]);
42        return;
43    }
44
45    let bindings: serde_json::Value = if args.len() == 3 {
46        serde_json::from_str(&args[2]).expect("Failed to parse bindings")
47    } else {
48        serde_json::from_str::<serde_json::Value>("{}").unwrap()
49    };
50
51    let prog = rscel::Program::from_source(&args[1]).expect("Failed to compile");
52    let ast = prog.details().ast().unwrap();
53
54    let dumper = AstDumper::new();
55    let tree = dumper.dump_expr_node(ast);
56
57    let mut queue = Vec::new();
58    queue.push((tree, 0));
59
60    while !queue.is_empty() {
61        let (curr_node, depth) = queue.pop().expect("wut");
62
63        // for now only handle one line
64        let range = curr_node.range();
65
66        let start = range.start().col();
67        let end = range.end().col();
68
69        let src = &args[1][start..end];
70
71        print!("{}{} => ", " ".to_owned().repeat(depth), src);
72        match eval(src, &bindings) {
73            Ok(val) => println!("{}", val),
74            Err(err) => println!("err: {}", err),
75        }
76
77        for node in curr_node.into_children().into_iter().rev() {
78            if node.range() != range {
79                queue.push((node, depth + 1));
80            }
81        }
82    }
83}

Trait Implementations§

Source§

impl Clone for SourceLocation

Source§

fn clone(&self) -> SourceLocation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceLocation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SourceLocation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Ord for SourceLocation

Source§

fn cmp(&self, other: &SourceLocation) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SourceLocation

Source§

fn eq(&self, other: &SourceLocation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SourceLocation

Source§

fn partial_cmp(&self, other: &SourceLocation) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for SourceLocation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for SourceLocation

Source§

impl Eq for SourceLocation

Source§

impl StructuralPartialEq for SourceLocation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,