kernel/src/main/java/org/kframework/parser/inner/kernel/EarleyParser.java
/**
   * Compute the CompleteParseTreeNode for a non-terminal and an input range from a parse tree that is
   * part of an {@link EarleyState} which has parsed an entire production.
   *
   * @param parses The set of parses to add new derivations to.
   * @param parseTree The parse tree of the {@link EarleyState} being processed.
   * @param eprod The {@link EarleyProduction} that was just parsed.
   * @param start The start-index of the input range that was parsed.
   * @param end The end-index of the input range that was parsed.
   * @param data The {@link ParserMetadata} about the current sentence being parsed.
   */
Compute the CompleteParseTreeNode for a non-terminal and an input range from a parse tree that is
part of an  EarleyState which has parsed an entire production.

@param parses The set of parses to add new derivations to.
@param parseTree The parse tree of the  EarleyState being processed.
@param eprod The  EarleyProduction that was just parsed.
@param start The start-index of the input range that was parsed.
@param end The end-index of the input range that was parsed.
@param data The  ParserMetadata about the current sentence being parsed.
Compute the CompleteParseTreeNode for a non - terminal and an input range from a parse tree that is part of an EarleyState which has parsed an entire production . @param parses The set of parses to add new derivations to . @param parseTree The parse tree of the EarleyState being processed . @param eprod The EarleyProduction that was just parsed . @param start The start - index of the input range that was parsed . @param end The end - index of the input range that was parsed . @param data The ParserMetadata about the current sentence being parsed .
private static void wrapState(Set<Term> parses, Set<PStack<Term>> parseTree, EarleyProduction eprod, int start, int end, ParserMetadata data) {
    for (PStack<Term> children : parseTree) {
      Production prod = eprod.prod;
      Term result;
      int startLoc = data.words[start].startLoc;
      int endLoc;
      if (start != end) {
        endLoc = data.words[end-1].endLoc;
      } else {
        endLoc = data.words[end].endLoc;
      }
      int startLine = data.lines[startLoc];
      int startColumn = data.columns[startLoc];
      int endLine = data.lines[endLoc];
      int endColumn = data.columns[endLoc];
      Location loc = new Location(startLine, startColumn, endLine, endColumn);
      if (eprod.isToken()) {
        String value = data.input.substring(startLoc, endLoc);
        if (eprod.isMInt()) {
          int index = value.indexOf('p');
          if (index == -1) {
            index = value.indexOf('P');
          }
          assert index != -1;
          String param = value.substring(index + 1);
          prod = prod.substitute(Seq(Sort(param)));
        }
        result = Constant.apply(value, prod, Optional.of(loc), Optional.of(data.source));
      } else if (eprod.needsLabel()) {
        result = TermCons.apply(children, prod, loc, data.source);
      } else {
        result = children.get(0);
      }
      parses.add(result);
    }
  }
private static void wrapState ( Set < Term > parses , Set < PStack < Term > > parseTree , EarleyProduction eprod , int start , int end , ParserMetadata data ) { for ( PStack < Term > children : parseTree ) { Production prod = eprod . prod ; Term result ; int startLoc = data . words [ start ] . startLoc ; int endLoc ; if ( start != end ) { endLoc = data . words [ end - 1 ] . endLoc ; } else { endLoc = data . words [ end ] . endLoc ; } int startLine = data . lines [ startLoc ] ; int startColumn = data . columns [ startLoc ] ; int endLine = data . lines [ endLoc ] ; int endColumn = data . columns [ endLoc ] ; Location loc = new Location ( startLine , startColumn , endLine , endColumn ) ; if ( eprod . isToken ( ) ) { String value = data . input . substring ( startLoc , endLoc ) ; if ( eprod . isMInt ( ) ) { int index = value . indexOf ( 'p' ) ; if ( index == - 1 ) { index = value . indexOf ( 'P' ) ; } assert index != - 1 ; String param = value . substring ( index + 1 ) ; prod = prod . substitute ( Seq ( Sort ( param ) ) ) ; } result = Constant . apply ( value , prod , Optional . of ( loc ) , Optional . of ( data . source ) ) ; } else if ( eprod . needsLabel ( ) ) { result = TermCons . apply ( children , prod , loc , data . source ) ; } else { result = children . get ( 0 ) ; } parses . add ( result ) ; } }
Compute the CompleteParseTreeNode for a non-terminal and an input range from a parse tree that is
 part of an {@link EarleyState} which has parsed an entire production.
Compute the CompleteParseTreeNode for a non - terminal and an input range from a parse tree that is part of an { @link EarleyState } which has parsed an entire production .
// compute the Location // it's a token, so create a Constant. // it's an MInt token, so make sure to add the correct bit-length to the production before creating the // Constant // it's a regular symbol, so create a TermCons // either a bracket or a subsort, therefore, create no node at all.