planetarypy / pvl

Python implementation of PVL (Parameter Value Language)
BSD 3-Clause "New" or "Revised" License
19 stars 19 forks source link

ISIS PVL strings with + characters in string values are not supported #59

Closed jessemapel closed 4 years ago

jessemapel commented 4 years ago

OS

MAC OS 10.13

Version

master @ be90a3e5425875828ca70e8fc66c67992559c64c

Bug

ISIS allows for + characters in string values, even though the general spec. does not. Attempting to read in an ISIS PVL with a + causes an error.

To reproduce

This is just a snippet of the full Cube label. I can provide that if needed too.

import pvl
pvl.loads("""
Object = NaifKeywords
  BODY_CODE                       = 499
  BODY499_RADII                   = (3396.19, 3396.19, 3376.2)
  BODY_FRAME_CODE                 = 10014
  INS-143400_SWAP_OBSERVER_TARGET = TRUE
  INS-143400_LIGHTTIME_CORRECTION = LT+S
  INS-143400_LT_SURFACE_CORRECT   = TRUE
  INS-143400_FOCAL_LENGTH         = 874.9
  INS-143400_PIXEL_PITCH          = 0.01
  INS-143400_TRANSX               = (0.0, 0.01, 0.0)
  INS-143400_TRANSY               = (0.0, 0.0, 0.01)
  INS-143400_ITRANSS              = (0.0, 100.0, 0.0)
  INS-143400_ITRANSL              = (0.0, 0.0, 100.0)
  INS-143400_BORESIGHT_SAMPLE     = 1024.5
  INS-143400_BORESIGHT_LINE       = 1024.5
  INS-143400_OD_A1_CORR           = (0.0037613053094827, -0.013415415606581,
                                     -1.86749521007237e-05, 1.0002135268184,
                                     -4.32362371703953e-04,
                                     -9.48065735350123e-04)
  INS-143400_OD_A2_CORR           = (9.9842559363676e-05, 0.0037354370795816,
                                     -0.013329991887393, -2.15311328389359e-04,
                                     0.99529601553729, -0.018354271771078)
  INS-143400_OD_A3_CORR           = (-3.13320167004204e-05,
                                     -7.35655125749807e-06,
                                     -1.57664245066771e-05, 0.0037354946543915,
                                     -0.014167194693093, 1.0)
  INS-143400_OD_A1_DIST           = (0.0021365879556062, -0.007117857650642,
                                     1.10355974742147e-05, 0.57360718262538,
                                     2.50884350194894e-04,
                                     5.50623913037132e-04)
  INS-143400_OD_A2_DIST           = (-5.69725741015406e-05,
                                     0.0021515590567915, -0.0071639299176719,
                                     1.24152787728634e-04, 0.57645954439243,
                                     0.010576940564854)
  INS-143400_OD_A3_DIST           = (1.78250771483506e-05,
                                     4.24592743471094e-06,
                                     9.51220699036653e-06, 0.0021515842542074,
                                     -0.0066835595774833, 0.57374154097161)
  INS-143400_FILTER_SAMPLES       = 2048.0
  INS-143400_FILTER_LINES         = 2048.0
End_Object
End
""")

Raises the following exception

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/lexer.py in lexer(s, g, d)
    429                     yield None
--> 430                     t = yield(t)
    431                 lexeme = ''

ValueError: Expecting an Aggregation Block, an Assignment Statement, or an End Statement, but found "+" 

During handling of the above exception, another exception occurred:

LexerError                                Traceback (most recent call last)
<ipython-input-4-601e6f5d514f> in <module>
     43 End_Object
     44 End
---> 45 """)

~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/__init__.py in loads(s, parser, grammar, decoder, **kwargs)
    148         raise TypeError('The parser must be an instance of pvl.PVLParser.')
    149 
--> 150     return parser.parse(s)
    151 
    152 

~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/parser.py in parse(self, s)
    764         self.doc = nodash
    765 
--> 766         return super().parse(nodash)
    767 
    768     def parse_module_post_hook(self, module, tokens: abc.Generator):

~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/parser.py in parse(self, s)
    186         """Converts the string, *s* to a PVLModule."""
    187         tokens = self.lexer(s, g=self.grammar, d=self.decoder)
--> 188         module = self.parse_module(tokens)
    189         module.errors = sorted(self.errors)
    190         return module

~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/parser.py in parse_module(self, tokens)
    254         t = next(tokens)
    255         tokens.throw(ValueError,
--> 256                      'Expecting an Aggregation Block, an Assignment '
    257                      'Statement, or an End Statement, but found '
    258                      f'"{t}" ')

~/miniconda3/envs/ale_pvl_test/lib/python3.7/site-packages/pvl-1.0.0a2-py3.7.egg/pvl/lexer.py in lexer(s, g, d)
    434 
    435         except ValueError as err:
--> 436             raise LexerError(err, s, i, lexeme)

LexerError: (LexerError(...), 'Expecting an Aggregation Block, an Assignment Statement, or an End Statement, but found "+" : line 7 column 39 (char 247)')
michaelaye commented 4 years ago

btw, is it much work to have the LexerError spit out the LINE where the error happens? Would be much easier for debugging?

rbeyer commented 4 years ago

It does. Scroll right.

jessemapel commented 4 years ago

Here's the offending keyword:

  INS-143400_LIGHTTIME_CORRECTION = LT+S
michaelaye commented 4 years ago

I would like to see the LINE not the LINE number? ;)

michaelaye commented 4 years ago

because in above label, i can not correlate line 7 with this error, even so i know from the error description that it must be the + in LT+S

rbeyer commented 4 years ago

Oh! Sorry, I misread that: derp. Yeah, LexerError needs more context on output, I agree. Added it to the Issue on Exceptions.