001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.compiler.parser;
011
012/**
013 * TokenManager extension allowing to track token offsets.
014 */
015public class GoloOffsetParserTokenManager extends GoloParserTokenManager {
016
017  public GoloOffsetParserTokenManager(JavaCharStream stream) {
018    super(new JavaOffsetCharStream(stream));
019  }
020
021  public GoloOffsetParserTokenManager(JavaCharStream stream, int lexState) {
022    super(new JavaOffsetCharStream(stream), lexState);
023  }
024
025  @Override
026  protected Token jjFillToken() {
027    Token t = super.jjFillToken();
028    if (input_stream instanceof JavaOffsetCharStream) {
029      t.startOffset = ((JavaOffsetCharStream) input_stream).getBeginOffset() - 1;
030      t.endOffset = ((JavaOffsetCharStream) input_stream).getCurrentOffset();
031    }
032    return t;
033  }
034}