-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for primitive json comments (#37)
To provide some support for comments within the test configs a simple JSON with comments decoder class has been introduced. This only provides support for leading // style comments in an effort to remain lightweight and work with native Python installs, no dependencies on external packages. This should prove sufficient to allow a modicum of annotation to test configs.
- Loading branch information
Showing
2 changed files
with
21 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# https://stackoverflow.com/a/72168909 | ||
import json | ||
from typing import Any | ||
class JSONCDecoder( json.JSONDecoder ): | ||
def __init__( self, **kw ) : | ||
super().__init__( **kw ) | ||
|
||
def decode( self, s : str ) -> Any : | ||
# Sanitize the input string for leading // comments ONLY and replace with | ||
# blank line so that line numbers are preserved | ||
s = '\n'.join( l if not l.lstrip().startswith( "//" ) else "" for l in s.split( '\n' ) ) | ||
return super().decode( s ) |
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