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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::fmt;

use serde::{Serialize, Deserialize};



/// Contains a percise location of error in the schema.
/// Attention! If it is required to compare locations, do
/// not use PartialEq as it always returns true which is used
/// for debug purposes. Use is_eq() to compare instances.
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize, Hash)]
pub struct LexerInfo
{
    pub(crate) line: u32,
    pub(crate) column: u32
}

impl LexerInfo
{
    /// Returns a dummy instance with line = 0 and column = 0.
    pub const
    fn notexistent() -> Self
    {
        return Self {line: 0, column: 0};
    }

    /// Checks if two instances are equal. Used as replacement to [PartialEq].
    pub 
    fn is_eq(&self, other: &Self) -> bool
    {
        return self.column == other.column && self.line == other.line;
    }

    /// Returns the line number.
    pub 
    fn get_line(&self) -> u32
    {
        return self.line;
    }

    /// Returns true if this instance is not dummy.
    pub 
    fn exists(&self) -> bool
    {
        return self.line != 0;
    }
}

impl PartialEq for LexerInfo 
{
    /// implemented for tests only! Use [LexerInfo::is_eq]
    fn eq(&self, _other: &Self) -> bool 
    {
        return true;
    }
}


impl fmt::Display for LexerInfo 
{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result 
    {
        write!(f, "line: {}, column: {}", self.line, self.column)
    }
}