java.lang.Object
java.lang.Record
dev.jcputney.elearning.parser.input.scorm12.adl.prerequisite.ParseError
Record Components:
originalExpression - the original expression string that failed to parse
errorMessage - a description of why parsing failed
errorPosition - the character position where the error was detected (0-based), or -1 if unknown
All Implemented Interfaces:
PrerequisiteExpression

public record ParseError(String originalExpression, String errorMessage, int errorPosition) extends Record implements PrerequisiteExpression
Represents a parse error when the prerequisite expression cannot be parsed.

This allows the parser to gracefully handle malformed expressions without throwing exceptions. Consumers can check if the result is a ParseError to determine if the expression was valid.

Example error scenarios:

  • Unbalanced parentheses: (ITEM-001 & ITEM-002
  • Missing operand: ITEM-001 &
  • Invalid characters: ITEM-001 @ ITEM-002
  • Empty expression: ""
  • Constructor Details

    • ParseError

      public ParseError(String originalExpression, String errorMessage)
      Creates a parse error with an unknown position.
      Parameters:
      originalExpression - the original expression string
      errorMessage - the error description
    • ParseError

      public ParseError(String originalExpression, String errorMessage, int errorPosition)
      Creates an instance of a ParseError record class.
      Parameters:
      originalExpression - the value for the originalExpression record component
      errorMessage - the value for the errorMessage record component
      errorPosition - the value for the errorPosition record component
  • Method Details

    • accept

      public <T> T accept(PrerequisiteExpression.Visitor<T> visitor)
      Description copied from interface: PrerequisiteExpression
      Accepts a visitor to process this expression.
      Specified by:
      accept in interface PrerequisiteExpression
      Type Parameters:
      T - the return type of the visitor
      Parameters:
      visitor - the visitor to accept
      Returns:
      the result of the visitor processing this expression
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • originalExpression

      public String originalExpression()
      Returns the value of the originalExpression record component.
      Returns:
      the value of the originalExpression record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • errorPosition

      public int errorPosition()
      Returns the value of the errorPosition record component.
      Returns:
      the value of the errorPosition record component