Changes between Initial Version and Version 1 of Ticket #498, comment 3


Ignore:
Timestamp:
Dec 7, 2016, 2:15:52 PM (9 years ago)
Author:
Greg Couch

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #498, comment 3

    initial v1  
    11The color command is registered as
    22
    3   color (ObjectsArg|EmptyArg) [ColorArg|SpecialColors]
     3  color (!ObjectsArg|!EmptyArg) [!ColorArg|S!pecialColors]
    44
    5 When parsing "color red", ObjectsArg.parse calls AtomSpecArg.parse which calls AtomSpecArg._parse_unquoted.  The parser (eventually) figures out that "red" is a word and calls _AtomSpecSemantics.selector_name to process it.  selector_name sees that "red" is not a registered selector and raises grako.FailedSemantics.  The problem is that it tries to set the "pos" and "endpos" attributes of the exception instance, but the parser catches the constructed FailedSemantics exception and reraises a grako.FailedParse exception.  The latter does not use our custom "pos" attributes (0 in this case); instead, it uses the "pos" constructed by the parser (3 in this case).  The FailedParse exception is caught by AtomSpecArg._parse_unquoted and converted to an AnnotationError with attribute "offset" set to "pos".  This AnnotationError is caught by Or.parse, which reraises the Annotation exception because "offset" is non-zero.
     5When parsing "color red", !ObjectsArg.parse calls !AtomSpecArg.parse which calls !AtomSpecArg._parse_unquoted.  The parser (eventually) figures out that "red" is a word and calls _AtomSpecSemantics.selector_name to process it.  selector_name sees that "red" is not a registered selector and raises grako.!FailedSemantics.  The problem is that it tries to set the "pos" and "endpos" attributes of the exception instance, but the parser catches the constructed !FailedSemantics exception and reraises a grako.!FailedParse exception.  The latter does not use our custom "pos" attributes (0 in this case); instead, it uses the "pos" constructed by the parser (3 in this case).  The !FailedParse exception is caught by !AtomSpecArg._parse_unquoted and converted to an !AnnotationError with attribute "offset" set to "pos".  This !AnnotationError is caught by Or.parse, which reraises the Annotation exception because "offset" is non-zero.
    66
    7 I'm reluctant to change the exception processing in parsing since FailedSemantics is the exception that the grako documentation recommends.  Changing Or.parse to ignore the offset value makes "color red" work, but I don't know what it breaks.  Greg?
     7I'm reluctant to change the exception processing in parsing since !FailedSemantics is the exception that the grako documentation recommends.  Changing Or.parse to ignore the offset value makes "color red" work, but I don't know what it breaks.  Greg?