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