diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-05-06 16:19:15 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-05-06 16:19:15 +1200 |
commit | e38f108921c61e1e66d65a368f2a67a763d61e69 (patch) | |
tree | 2718330c1e9963a21bc08db3ddc18574b078d004 /src/addressing.rs | |
download | bedrock-asm-e38f108921c61e1e66d65a368f2a67a763d61e69.zip |
About to refactor parser to be a struct with a method for each stage
Diffstat (limited to 'src/addressing.rs')
-rw-r--r-- | src/addressing.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/addressing.rs b/src/addressing.rs new file mode 100644 index 0000000..dd7638e --- /dev/null +++ b/src/addressing.rs @@ -0,0 +1,44 @@ +#[derive(Clone,Copy)] +pub struct CharAddress { + /// The number of lines that precede this line in the file. + pub line:usize, + /// The number of characters that precede this character in the line. + pub column:usize, +} +impl CharAddress { + pub fn new(line:usize, column:usize) -> Self { + Self { line, column } + } + pub fn zero() -> Self { + Self::new(0,0) + } +} + +pub struct SourceLocation { + /// The slice of the source file from which this token was parsed. + pub source: String, + /// The address of the first character of this token. + pub start: CharAddress, + /// The address of the final character of this token. + pub end: CharAddress +} +impl SourceLocation { + pub fn new(source:String, start:CharAddress, end:CharAddress) -> Self { + Self { source, start, end } + } + pub fn zero() -> Self { + Self { source:String::new(), start:CharAddress::zero(), end:CharAddress::zero() } + } +} + +pub struct BytecodeLocation { + /// The number of bytes that precede this byte sequence in the bytecode. + pub start: u16, + /// The length of this byte sequence, in bytes. + pub length: u16, +} +impl BytecodeLocation { + pub fn zero() -> Self { + Self { start:0, length:0 } + } +} |