-
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.
Merge pull request #5 from fmi-faim/single-plane
Switch to lark for parsing nd file contents
- Loading branch information
Showing
7 changed files
with
164 additions
and
83 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
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,36 @@ | ||
from lark import Lark, Transformer | ||
|
||
|
||
class NDInfoTransformer(Transformer): | ||
def __init__(self): | ||
self.wave_names = [] | ||
self.wave_do_z = [] | ||
self.stage_positions = [] | ||
|
||
def start(self, items): | ||
result = dict(i for i in items if i is not None) | ||
result["WaveNames"] = self.wave_names | ||
result["WaveDoZ"] = self.wave_do_z | ||
result["StagePositions"] = self.stage_positions | ||
return result | ||
|
||
def line(self, key_value): | ||
key, value = key_value | ||
if key.startswith("WaveName"): | ||
self.wave_names.append(value) | ||
return None # We handle WaveName entries separately | ||
if key.startswith("Stage"): | ||
self.stage_positions.append(value) | ||
return None # We handle Stage entries separately | ||
if key.startswith("WaveDoZ"): | ||
self.wave_do_z.append(value) | ||
return None # We handle WaveDoZ entries separately | ||
return (key, value) | ||
|
||
def boolean_value(self, b): | ||
return b[0].value == "TRUE" | ||
|
||
|
||
def parse(content): | ||
parser = Lark.open("nd_grammar.lark", rel_to=__file__, parser="lalr", transformer=NDInfoTransformer()) | ||
return parser.parse(content) |
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,40 @@ | ||
start: line+ "\"EndFile\"" | ||
line: _QUOTE _special_key _QUOTE "," _special_value | ||
| _QUOTE _string_key _QUOTE "," _QUOTE _string_value _QUOTE | ||
| _QUOTE _boolean_key _QUOTE "," boolean_value | ||
| _QUOTE _integer_key _QUOTE "," _integer_value | ||
| _QUOTE _float_key _QUOTE "," _float_value | ||
|
||
_special_key: /NDInfoFile/ | ||
| /Description/ | ||
| /StartTime[0-9]+/ | ||
_special_value: /.+/ | ||
|
||
_string_key: /WaveName[0-9]+/ | ||
| /Stage[0-9]+/ | ||
_string_value: /[^"]+/ | ||
|
||
_boolean_key: /DoTimelapse/ | ||
| /DoStage/ | ||
| /DoWave/ | ||
| /DoZSeries/ | ||
| /WaveInFileName/ | ||
| /WaveDoZ[0-9]+/ | ||
boolean_value: BOOLEAN | ||
|
||
_integer_key: /NWavelengths/ | ||
| /NStagePositions/ | ||
| /NTimePoints/ | ||
| /NZSteps/ | ||
_integer_value: INT | ||
|
||
_float_key: /ZStepSize/ | ||
_float_value: DECIMAL | INT | ||
|
||
%import common.INT | ||
%import common.DECIMAL | ||
%import common.WS | ||
%ignore WS | ||
|
||
BOOLEAN: "TRUE" | "FALSE" | ||
_QUOTE: "\"" |
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,14 @@ | ||
"NDInfoFile", Version 1.0 | ||
"Description", File recreated from images. | ||
"StartTime1", 20240603 12:25:48.610 | ||
"DoTimelapse", FALSE | ||
"DoStage", FALSE | ||
"DoWave", TRUE | ||
"NWavelengths", 4 | ||
"WaveName1", "confDAPI" | ||
"WaveName2", "confGFP" | ||
"WaveName3", "confmCherry" | ||
"WaveName4", "confCy5" | ||
"DoZSeries", FALSE | ||
"WaveInFileName", TRUE | ||
"EndFile" |
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