M2.1: tree-sitter PHP in crates/syntax
Parser (parse, incremental reparse from lutra_text edits), outline with UTF-16 ranges and short signatures, folding ranges, 8 MiB parse cap. Snapshot tests for five PHP 8.3 fixtures, proptests (random bytes, reparse equals fresh parse, undo round trip), ignored release timing test. Docs: architecture Syntax section, parity evidence, G4 note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d12a517009
commit
a5236acd7e
25 changed files with 1768 additions and 6 deletions
28
crates/syntax/src/range.rs
Normal file
28
crates/syntax/src/range.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//! Ranges in line and UTF-16 column coordinates.
|
||||
|
||||
use lutra_text::{Buffer, ColumnUnit, Position};
|
||||
|
||||
/// A range between two positions, end exclusive.
|
||||
///
|
||||
/// Lines and columns are zero-based; columns count UTF-16 code units, as
|
||||
/// CodeMirror and LSP do.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
pub struct Range {
|
||||
/// First position inside the range.
|
||||
pub start: Position,
|
||||
/// Position just after the range.
|
||||
pub end: Position,
|
||||
}
|
||||
|
||||
impl Range {
|
||||
/// Converts the byte range `start..end` of `text` into a [`Range`].
|
||||
///
|
||||
/// Returns `None` when either offset is past the end of the text, inside
|
||||
/// a character or inside a CRLF line break.
|
||||
pub(crate) fn from_bytes(text: &Buffer, start: usize, end: usize) -> Option<Self> {
|
||||
Some(Self {
|
||||
start: text.offset_to_position(start, ColumnUnit::Utf16).ok()?,
|
||||
end: text.offset_to_position(end, ColumnUnit::Utf16).ok()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue