-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support passing a file via standard input (#260)
* If the argument "-" is passed, that tells precli to read the file from stdin. * Use the existing dependency of rich and Pygments to guess the lexer since there is no file name in this case. * This change also gets rid of the file extension logic of the parsers and just keeps a lexer name instead. Closes #214 Signed-off-by: Eric Brown <[email protected]>
- Loading branch information
Showing
13 changed files
with
116 additions
and
37 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
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 @@ | ||
# Copyright 2024 Secure Saurce LLC | ||
import linecache | ||
|
||
|
||
class LineCache: | ||
def __init__(self, file_name: str, file_contents: str): | ||
""" | ||
Initialize the cache with the given file contents. | ||
:param file_name: Name of the file (can be <stdin>. | ||
:param file_contents: A string containing the entire file data. | ||
""" | ||
self._file_name = file_name | ||
if self._file_name == "<stdin>": | ||
self._lines = file_contents.splitlines(keepends=True) | ||
|
||
def getline(self, lineno: int) -> str: | ||
""" | ||
Return the line from the file contents at the given line number. | ||
:param lineno: The line number to fetch, 1-based. | ||
:return: The line at the specified line number, or an empty string if | ||
the line does not exist. | ||
""" | ||
if self._file_name != "<stdin>": | ||
return linecache.getline(self._file_name, lineno) | ||
else: | ||
if 0 < lineno <= len(self._lines): | ||
return self._lines[lineno - 1] | ||
return "" |
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
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
# Copyright 2023 Secure Saurce LLC | ||
# Copyright 2024 Secure Saurce LLC | ||
from precli.parsers import Parser | ||
|
||
|
||
class Java(Parser): | ||
def __init__(self, enabled: list = None, disabled: list = None): | ||
super().__init__("java", enabled, disabled) | ||
|
||
def file_extension(self) -> str: | ||
return ".java" |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
cwe | ||
Pygments | ||
rich # MIT | ||
tree_sitter>=0.20.4 | ||
tree-sitter-languages>=1.9.1 | ||
|