-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: now ignores Go compile directives
- Loading branch information
1 parent
9d09099
commit 66332dc
Showing
11 changed files
with
158 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30380,6 +30380,7 @@ lineage/MS | |
lineal/Y | ||
lineament/SM | ||
linear/Y | ||
superlinear/Y | ||
linearity/M | ||
linebacker/MS | ||
lined/U | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use harper_core::parsers::{Markdown, Parser}; | ||
use harper_core::Token; | ||
|
||
use super::without_intiators; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct Go; | ||
|
||
impl Parser for Go { | ||
fn parse(&mut self, source: &[char]) -> Vec<Token> { | ||
let mut actual = without_intiators(source); | ||
let mut actual_source = actual.get_content(source); | ||
|
||
if matches!(source, ['g', 'o', ':', ..]) { | ||
let Some(terminator) = source.iter().position(|c| c.is_whitespace()) else { | ||
return Vec::new(); | ||
}; | ||
|
||
actual.start += terminator; | ||
|
||
let Some(new_source) = actual.try_get_content(actual_source) else { | ||
return Vec::new(); | ||
}; | ||
|
||
actual_source = new_source | ||
} | ||
|
||
let mut markdown_parser = Markdown; | ||
|
||
let mut new_tokens = markdown_parser.parse(actual_source); | ||
|
||
new_tokens | ||
.iter_mut() | ||
.for_each(|t| t.span.offset(actual.start)); | ||
|
||
new_tokens | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
mod go; | ||
mod unit; | ||
|
||
pub use go::Go; | ||
use harper_core::Span; | ||
pub use unit::Unit; | ||
|
||
/// Get the span of a tree-sitter-produced comment that doesn't include the | ||
/// comment openers and closers. | ||
fn without_intiators(source: &[char]) -> Span { | ||
// Skip over the comment start characters | ||
let actual_start = source | ||
.iter() | ||
.position(|c| !is_comment_character(*c)) | ||
.unwrap_or(0); | ||
|
||
// Chop off the end | ||
let actual_end = source.len() | ||
- source | ||
.iter() | ||
.rev() | ||
.position(|c| !is_comment_character(*c)) | ||
.unwrap_or(0); | ||
|
||
Span::new(actual_start, actual_end) | ||
} | ||
|
||
fn is_comment_character(c: char) -> bool { | ||
matches!(c, '#' | '-' | '/' | '*') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use harper_core::parsers::{Markdown, Parser}; | ||
use harper_core::Token; | ||
|
||
use super::without_intiators; | ||
|
||
/// A comment parser that strips starting `/` and `*` characters. | ||
/// | ||
/// It is meant to cover _most_ cases in _most_ programming languages. | ||
/// | ||
/// It assumes it is being provided a single line of comment at a time, | ||
/// including the comment initiation characters. | ||
pub struct Unit; | ||
|
||
impl Parser for Unit { | ||
fn parse(&mut self, source: &[char]) -> Vec<Token> { | ||
let actual = without_intiators(source); | ||
let source = actual.get_content(source); | ||
|
||
let mut markdown_parser = Markdown; | ||
|
||
let mut new_tokens = markdown_parser.parse(source); | ||
|
||
new_tokens | ||
.iter_mut() | ||
.for_each(|t| t.span.offset(actual.start)); | ||
|
||
new_tokens | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters