ParseError.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 27 Oct 2022 14:53:59 +0100
branchjv
changeset 4735 3b11fb3ede98
parent 4650 e9b212d470ff
permissions -rw-r--r--
Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e.

"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libcomp' }"

"{ NameSpace: Smalltalk }"

ProceedableError subclass:#ParseError
	instanceVariableNames:'errorMessage startPosition endPosition lineNumber'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler'
!

!ParseError class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    raised for any compilation-related errors.
    (originally, I wanted to subclass this from compilationError,
    and raise different error for code generator issues (i.e. method too
    big, etc.) But all users of the parser in the system (RB-stuff, Lint stuff,
    fileIn etc.) always handle the ParseError, and I don't want them to be forced to change.
    So we subclass the codeGenerator issues from this one.
"
! !

!ParseError methodsFor:'accessing'!

description
    "construct the description from my default description (i.e. 'Parse Error:'),
     followed by the actual parse-error-message, followed by the lineNumber (if known)"
     
    |s|

    s := super description.
    
    s last isSeparator ifFalse:[
        errorMessage notEmptyOrNil ifTrue:[
            s := s , ' '
        ]
    ].
    s := s , (errorMessage ? '').
    lineNumber notNil ifTrue:[
        "/ avoid redundant information (in case the line number is already in the description)
        (s includesString:'[Line:') ifFalse:[
            s := s , ' [Line ' , lineNumber asString , ']'
        ].
    ].
    ^ s
!

endPosition
    "the end-tokenposition, where the error is located"

    ^ endPosition
!

endPosition:anInteger
    "the end-tokenposition, where the error is located"
    
    endPosition := anInteger.
!

errorMessage
    ^ errorMessage
!

errorMessage:aString
    errorMessage := aString.
!

errorMessage:errorMessageArg startPosition:startPositionArg 
    errorMessage := errorMessageArg.
    startPosition := startPositionArg.
!

errorMessage:errorMessageArg startPosition:startPositionArg endPosition:endPositionArg 
    errorMessage := errorMessageArg.
    startPosition := startPositionArg.
    endPosition := endPositionArg.
!

lineNumber
    "the lineNumber, where the error was detected"

    ^ lineNumber
!

lineNumber:anInteger
    "the lineNumber, where the error was detected"
    
    lineNumber := anInteger.
!

parser
    ^ originator
!

startPosition
    "the start-tokenposition, where the error is located"

    ^ startPosition
!

startPosition:anInteger
    "the start-tokenposition, where the error is located"
    
    startPosition := anInteger.
!

startPosition:startPositionArg endPosition:endPositionArg 
    startPosition := startPositionArg.
    endPosition := endPositionArg.
! !

!ParseError methodsFor:'compatibility - VW'!

position
    ^ startPosition

    "Created: / 03-05-2020 / 23:44:48 / cg"
! !

!ParseError class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !