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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Placeholder script character position type.
#![cfg(feature = "no_position")]
#![allow(unused_variables)]
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
fmt,
ops::{Add, AddAssign},
};
/// A location (line number + character position) in the input script.
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, Default)]
pub struct Position;
impl Position {
/// A [`Position`] representing no position.
pub const NONE: Self = Self;
/// A [`Position`] representing the first position.
pub const START: Self = Self;
/// Create a new [`Position`].
#[inline(always)]
#[must_use]
pub const fn new(line: u16, position: u16) -> Self {
Self
}
/// Get the line number (1-based), or [`None`] if there is no position.
///
/// Always returns [`None`].
#[inline(always)]
#[must_use]
pub const fn line(self) -> Option<usize> {
None
}
/// Get the character position (1-based), or [`None`] if at beginning of a line.
///
/// Always returns [`None`].
#[inline(always)]
#[must_use]
pub const fn position(self) -> Option<usize> {
None
}
/// Advance by one character position.
#[inline(always)]
pub(crate) fn advance(&mut self) {}
/// Go backwards by one character position.
#[inline(always)]
pub(crate) fn rewind(&mut self) {}
/// Advance to the next line.
#[inline(always)]
pub(crate) fn new_line(&mut self) {}
/// Is this [`Position`] at the beginning of a line?
///
/// Always returns `false`.
#[inline(always)]
#[must_use]
pub const fn is_beginning_of_line(self) -> bool {
false
}
/// Is there no [`Position`]?
///
/// Always returns `true`.
#[inline(always)]
#[must_use]
pub const fn is_none(self) -> bool {
true
}
/// Returns an fallback [`Position`] if it is [`NONE`][Position::NONE]?
///
/// Always returns the fallback.
#[inline(always)]
#[must_use]
pub const fn or_else(self, pos: Self) -> Self {
pos
}
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "none")
}
}
impl fmt::Debug for Position {
#[cold]
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("none")
}
}
impl Add for Position {
type Output = Self;
#[inline(always)]
fn add(self, rhs: Self) -> Self::Output {
Self
}
}
impl AddAssign for Position {
#[inline(always)]
fn add_assign(&mut self, rhs: Self) {}
}
/// _(internals)_ A span consisting of a starting and an ending [positions][Position].
/// Exported under the `internals` feature only.
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, Default)]
pub struct Span;
impl Span {
/// Empty [`Span`].
pub const NONE: Self = Self;
/// Create a new [`Span`].
#[inline(always)]
#[must_use]
pub const fn new(start: Position, end: Position) -> Self {
Self
}
/// Is this [`Span`] non-existent?
///
/// Always returns `true`.
#[inline(always)]
#[must_use]
pub const fn is_none(&self) -> bool {
true
}
/// Get the [`Span`]'s starting [position][Position].
///
/// Always returns [`Position::NONE`].
#[inline(always)]
#[must_use]
pub const fn start(&self) -> Position {
Position::NONE
}
/// Get the [`Span`]'s ending [position][Position].
///
/// Always returns [`Position::NONE`].
#[inline(always)]
#[must_use]
pub const fn end(&self) -> Position {
Position::NONE
}
}
impl fmt::Display for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let f = f;
write!(f, "{:?}", Position)
}
}
impl fmt::Debug for Span {
#[cold]
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}