Generate a formatted abbreviation AtomSymbol for the given Hydrogen position.

@param tokens   the parsed tokens
@param position hydrogen position - determines if we reverse the label
@return the generated symbol
323424
AtomSymbol generateAbbreviationSymbol(List<String> tokens, HydrogenPosition position) {

        if (position == Left)
            AbbreviationLabel.reverse(tokens);

        final TextOutline tmpRefPoint = new TextOutline("H", font);
        final List<FormattedText> fTexts = AbbreviationLabel.format(tokens);

        final Font italicFont = font.deriveFont(Font.ITALIC);

        if (position == Below || position == Above)
            AbbreviationLabel.reduce(fTexts, 1, fTexts.size());
        else
            AbbreviationLabel.reduce(fTexts, 0, fTexts.size());

        // convert to outlines
        final List<TextOutline> outlines = new ArrayList<>(fTexts.size());
        for (FormattedText fText : fTexts) {

            TextOutline outline = fText.style == AbbreviationLabel.STYLE_ITALIC
                                  ? new TextOutline(fText.text, italicFont)
                                  : new TextOutline(fText.text, font);

            // resize and position scripts
            if (fText.style == AbbreviationLabel.STYLE_SUBSCRIPT) {
                outline = outline.resize(scriptSize, scriptSize);
                outline = positionSubscript(tmpRefPoint, outline);
            } else if (fText.style == AbbreviationLabel.STYLE_SUPSCRIPT) {
                outline = outline.resize(scriptSize, scriptSize);
                outline = positionSuperscript(tmpRefPoint, outline);
            }

            outlines.add(outline);
        }

        // position the outlines relative to each other
        for (int i = 1; i < outlines.size(); i++) {
            TextOutline ref = outlines.get(i - 1);
            TextOutline curr = outlines.get(i);
            // charge aligns to symbol not a subscript part
            if (fTexts.get(i).style == AbbreviationLabel.STYLE_SUPSCRIPT &&
                fTexts.get(i - 1).style == AbbreviationLabel.STYLE_SUBSCRIPT && i > 1) {
                ref = outlines.get(i - 2);
            }
            outlines.set(i, positionAfter(ref, curr));
        }

        // find symbol where we want to attach the bond
        // this becomes the primary outline
        int index;
        if (position == Left) {
            for (index = outlines.size() - 1; index >= 0; index--)
                if ((fTexts.get(index).style & 0x1) == 0) break;
        } else {
            for (index = 0; index < outlines.size(); index++)
                if ((fTexts.get(index).style & 0x1) == 0) break;
        }

        TextOutline primary = outlines.remove(index);

        if (position == Below || position == Above) {
            double offsetX = primary.getBounds().getX() - outlines.get(0).getBounds().getX();
            double offsetY = position == Below
                             ? padding + primary.getBounds().getHeight()
                             : -primary.getBounds().getHeight() - padding;
            for (int i = 0; i < outlines.size(); i++) {
                outlines.set(i, outlines.get(i).translate(offsetX, offsetY));
            }
        }

        return new AtomSymbol(primary, outlines);
    }
1255203
private static String nextToken(String[] tokens, int x, String context)
            throws ParseException {
        if (x < tokens.length) {
            return tokens[x];
        }
        throw new ParseException("missing token at end of '" + context + "'", -1);
    }
1255217
public static StringBuilder under_score(final StringBuilder sb, final String... tokens) {
        return Strings.join(sb, "_", allToLower(tokens));
    }
129751
private String identifyAtomicSymbol(int atomicNumber) {
        String symbol;
        switch (atomicNumber) {
            case 1:
                symbol = "H";
                break;
            case 2:
                symbol = "He";
                break;
            case 3:
                symbol = "Li";
                break;
            case 4:
                symbol = "Be";
                break;
            case 5:
                symbol = "B";
                break;
            case 6:
                symbol = "C";
                break;
            case 7:
                symbol = "N";
                break;
            case 8:
                symbol = "O";
                break;
            case 9:
                symbol = "F";
                break;
            case 10:
                symbol = "Ne";
                break;
            case 11:
                symbol = "Na";
                break;
            case 12:
                symbol = "Mg";
                break;
            case 13:
                symbol = "Al";
                break;
            case 14:
                symbol = "Si";
                break;
            case 15:
                symbol = "P";
                break;
            case 16:
                symbol = "S";
                break;
            case 17:
                symbol = "Cl";
                break;
            case 18:
                symbol = "Ar";
                break;
            default:
                symbol = null;
                break;
        }
        return symbol;
    }
1006837
public static StringBuilder UNDER_SCORE(final StringBuilder sb, final String... tokens) {
        return Strings.join(sb, "_", allToUpper(tokens));
    }
826964
public static SymbolToken[] newSymbolTokens(SymbolTable symtab,
                                                String... text)
    {
        if (text != null)
        {
            int count = text.length;
            if (count != 0)
            {
                SymbolToken[] result = new SymbolToken[count];
                for (int i = 0; i < count; i++)
                {
                    String s = text[i];
                    result[i] = newSymbolToken(symtab, s);
                }
                return result;
            }
        }
        return SymbolToken.EMPTY_ARRAY;
    }
125542
private void label(final ITetrahedralChirality element) {

        final IAtom focus = element.getChiralAtom();
        final IAtom[] atoms = element.getLigands();
        final IBond[] bonds = new IBond[4];

        int p = parity(element.getStereo());
        int n = 0;

        // unspecified centre, no need to assign labels
        if (p == 0) return;

        for (int i = 0; i < 4; i++) {
            if (atoms[i].equals(focus)) {
                p *= indexParity(i); // implicit H, adjust parity
            } else {
                bonds[n] = container.getBond(focus, atoms[i]);
                if (bonds[n] == null)
                    throw new IllegalArgumentException("Inconsistent stereo,"
                                                       + " tetrahedral centre"
                                                       + " contained atom not"
                                                       + " stored in molecule");
                atoms[n] = atoms[i];
                n++;
            }
        }

        // sort coordinates and adjust parity (rank gives us the sorted order)
        int[] rank = new int[n];
        for (int i = 0; i < n; i++)
            rank[i] = i;
        p *= sortClockwise(rank, focus, atoms, n);

        // special case when there are three neighbors are acute and an implicit
        // hydrogen is opposite all three neighbors. The central label needs to
        // be inverted, atoms could be laid out like this automatically, consider
        // CC1C[C@H]2CC[C@@H]1C2
        int invert = -1;
        if (n == 3) {
            // find a triangle of non-sequential neighbors (sorted clockwise)
            // which has anti-clockwise winding
            for (int i = 0; i < n; i++) {
                Point2d a = atoms[rank[i]].getPoint2d();
                Point2d b = focus.getPoint2d();
                Point2d c = atoms[rank[(i + 2) % n]].getPoint2d();
                double det = (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);
                if (det > 0) {
                    invert = rank[(i + 1) % n];
                    break;
                }
            }
        }

        // assign all up/down labels to an auxiliary array
        IBond.Stereo[] labels = new IBond.Stereo[n];
        for (int i = 0; i < n; i++) {
            int v = rank[i];

            // 4 neighbors (invert every other one)
            if (n == 4) p *= -1;

            labels[v] = invert == v ? p > 0 ? DOWN : UP : p > 0 ? UP : DOWN;
        }

        // set the label for the highest priority and available bond
        IBond.Stereo firstlabel      = null;
        boolean      assignTwoLabels = assignTwoLabels(bonds, labels);
        for (int v : priority(atomToIndex.get(focus), atoms, n)) {
            IBond bond = bonds[v];
            if (bond.getStereo() != NONE || bond.getOrder() != SINGLE)
                continue;
            // first label
            if (firstlabel == null) {
                bond.setAtoms(new IAtom[]{focus, atoms[v]}); // avoids UP_INVERTED/DOWN_INVERTED
                bond.setStereo(labels[v]);
                firstlabel = labels[v];
                // don't assign a second label when there are only three ligands
                if (!assignTwoLabels)
                    break;
            }
            // second label
            else if (labels[v] != firstlabel) {
                // don't add if it's possibly a stereo-centre
                if (isSp3Carbon(atoms[v], graph[container.indexOf(atoms[v])].length))
                    break;
                bond.setAtoms(new IAtom[]{focus, atoms[v]}); // avoids UP_INVERTED/DOWN_INVERTED
                bond.setStereo(labels[v]);
                break;
            }
        }

        // it should be possible to always assign labels somewhere -> unchecked exception
        if (firstlabel == null)
            throw new IllegalArgumentException("could not assign non-planar (up/down) labels");
    }
1083039
protected function catchAsStringUntilSemicolon(array $tokens, $pos) {
        $t = count($tokens);
        $catched = null;
        for ($i = $pos; $i < $t; $i++) {
            if ($tokens[$i] == ';')
                return $catched;
            else if ($tokens[$i] == '\\')
                $catched .= '\\';
            else if (is_array($tokens[$i])) {
                $catched .= $tokens[$i][1];
            }
        }
        return $catched;
    }
60439
public final Span[] seqToSpans(final String[] tokens) {
    final Span[] annotatedText = this.sequenceLabeler.tag(tokens);
    final List<Span> probSpans = new ArrayList<Span>(
        Arrays.asList(annotatedText));
    return probSpans.toArray(new Span[probSpans.size()]);
  }
1267039
function identifierEndPosition( $tpl, &$text, $start_pos, $len )
    {
        $pos = $start_pos;
        while ( $pos < $len )
        {
            if ( !preg_match( "/^[a-zA-Z0-9_-]$/", $text[$pos] ) )
            {
                return $pos;
            }
            ++$pos;
        }
        return $pos;
    }
278900
public static int positionFor(final Symbol sym, final JCTree tree) {
        JCTree decl = declarationFor(sym, tree);
        return ((decl != null) ? decl : tree).pos;
    }
725344
function getExpectedIndent (tokens) {
    const trivial = isTrivialToken(tokens[0])
    let expectedIndent = Number.MAX_SAFE_INTEGER

    for (let i = 0; i < tokens.length; ++i) {
      const token = tokens[i]
      const offsetInfo = offsets.get(token)

      // If the first token is not trivial then ignore trivial following tokens.
      if (offsetInfo != null && (trivial || !isTrivialToken(token))) {
        if (offsetInfo.expectedIndent != null) {
          expectedIndent = Math.min(expectedIndent, offsetInfo.expectedIndent)
        } else {
          const baseOffsetInfo = offsets.get(offsetInfo.baseToken)
          if (baseOffsetInfo != null && baseOffsetInfo.expectedIndent != null && (i === 0 || !baseOffsetInfo.baseline)) {
            expectedIndent = Math.min(expectedIndent, baseOffsetInfo.expectedIndent + offsetInfo.offset * options.indentSize)
            if (baseOffsetInfo.baseline) {
              break
            }
          }
        }
      }
    }

    return expectedIndent
  }
1225904
private String escapeToken(String token) {
		String newToken = (String) escMap.get(token);
		if (newToken == null)
			return token;
		return newToken;
	}
1170434
final public void addPositions(int[] positions) {
    if (positions != null && positions.length > 0) {
      if (tokenPosition == null) {
        tokenPosition = new MtasPosition(positions);
      } else {
        tokenPosition.add(positions);
      }
    }
  }
24659
static String cssContent(String token) {
    int n = token.length();
    int pos = 0;
    StringBuilder sb = null;
    if (n >= 2) {
      char ch0 = token.charAt(0);
      if (ch0 == '"' || ch0 == '\'') {
        if (ch0 == token.charAt(n - 1)) {
          pos = 1;
          --n;
          sb = new StringBuilder(n);
        }
      }
    }
    for (int esc; (esc = token.indexOf('\\', pos)) >= 0;) {
      int end = esc + 2;
      if (esc > n) { break; }
      if (sb == null) { sb = new StringBuilder(n); }
      sb.append(token, pos, esc);
      int codepoint = token.charAt(end - 1);
      if (isHex(codepoint)) {
        // Parse \hhhhh<opt-break> where hhhhh is one or more hex digits
        // and <opt-break> is an optional space or tab character that can be
        // used to separate an escape sequence from a following literal hex
        // digit.
        while (end < n && isHex(token.charAt(end))) { ++end; }
        try {
          codepoint = Integer.parseInt(token.substring(esc + 1, end), 16);
        } catch (RuntimeException ex) {
          ignore(ex);
          codepoint = 0xfffd;  // Unknown codepoint.
        }
        if (end < n) {
          char ch = token.charAt(end);
          if (ch == ' ' || ch == '\t') {  // Ignorable hex follower.
            ++end;
          }
        }
      }
      sb.appendCodePoint(codepoint);
      pos = end;
    }
    if (sb == null) { return token; }
    return sb.append(token, pos, n).toString();
  }
851156
def append_position_to_token_list(token_list):
    """"""
    return [PositionToken(value.content, value.gd, index, index+1) for (index, value) in enumerate(token_list)]
353856
private String getTokenOrBlank(final List<String> tokens, final int reverseIndex) {

		final int length = tokens.size();
		final int index  = length - reverseIndex - 1;

		if (index >= 0 && length > 0 && index < length) {
			return tokens.get(index);
		}

		return "";
	}