Throw exceptions (not errors) from lexer
+ Add more data to the exception message
This commit is contained in:
@@ -36,6 +36,12 @@
|
|||||||
<target name="lexer">
|
<target name="lexer">
|
||||||
<flex flexfile="${home}/src/org/jetbrains/jet/lexer/Jet.flex"
|
<flex flexfile="${home}/src/org/jetbrains/jet/lexer/Jet.flex"
|
||||||
destdir="${home}/src/org/jetbrains/jet/lexer/"/>
|
destdir="${home}/src/org/jetbrains/jet/lexer/"/>
|
||||||
|
|
||||||
|
<!-- This is a hack, but we don't want to alter the skeleton we are using now, because being in sync with IDEA is more important-->
|
||||||
|
<replaceregexp file="${home}/src/org/jetbrains/jet/lexer/_JetLexer.java"
|
||||||
|
match="throw new KotlinLexerException\(message\);"
|
||||||
|
replace="throw new KotlinLexerException(message + "\\\\n at '" + yytext() + "'\\\\n" + zzBuffer);"/>
|
||||||
|
|
||||||
<flex flexfile="${home}/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex"
|
<flex flexfile="${home}/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex"
|
||||||
destdir="${home}/src/org/jetbrains/jet/kdoc/lexer/"/>
|
destdir="${home}/src/org/jetbrains/jet/kdoc/lexer/"/>
|
||||||
</target>
|
</target>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* The following code was generated by JFlex 1.4.3 on 3/6/14 2:29 PM */
|
/* The following code was generated by JFlex 1.4.3 on 5/27/14 6:17 PM */
|
||||||
|
|
||||||
package org.jetbrains.jet.kdoc.lexer;
|
package org.jetbrains.jet.kdoc.lexer;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ import java.lang.Character;
|
|||||||
/**
|
/**
|
||||||
* This class is a scanner generated by
|
* This class is a scanner generated by
|
||||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||||
* on 3/6/14 2:29 PM from the specification file
|
* on 5/27/14 6:17 PM from the specification file
|
||||||
* <tt>/Users/abreslav/work/kotlin/compiler/frontend/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex</tt>
|
* <tt>/Users/abreslav/work/kotlin/compiler/frontend/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex</tt>
|
||||||
*/
|
*/
|
||||||
class _KDocLexer implements FlexLexer {
|
class _KDocLexer implements FlexLexer {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.intellij.lexer.*;
|
|||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
|
import org.jetbrains.jet.lexer.KotlinLexerException;
|
||||||
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
@@ -60,6 +61,8 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%scanerror KotlinLexerException
|
||||||
|
|
||||||
%function advance
|
%function advance
|
||||||
%type IElementType
|
%type IElementType
|
||||||
%eof{
|
%eof{
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lexer;
|
||||||
|
|
||||||
|
public class KotlinLexerException extends RuntimeException {
|
||||||
|
public KotlinLexerException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* The following code was generated by JFlex 1.4.3 on 5/14/14 2:02 PM */
|
/* The following code was generated by JFlex 1.4.3 on 5/27/14 6:17 PM */
|
||||||
|
|
||||||
package org.jetbrains.jet.lexer;
|
package org.jetbrains.jet.lexer;
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ import com.intellij.lexer.*;
|
|||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
|
import org.jetbrains.jet.lexer.KotlinLexerException;
|
||||||
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
@@ -14,8 +15,8 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
/**
|
/**
|
||||||
* This class is a scanner generated by
|
* This class is a scanner generated by
|
||||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||||
* on 5/14/14 2:02 PM from the specification file
|
* on 5/27/14 6:17 PM from the specification file
|
||||||
* <tt>/Users/svtk/Kotlin/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
* <tt>/Users/abreslav/work/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||||
*/
|
*/
|
||||||
class _JetLexer implements FlexLexer {
|
class _JetLexer implements FlexLexer {
|
||||||
/** initial size of the lookahead buffer */
|
/** initial size of the lookahead buffer */
|
||||||
@@ -769,7 +770,7 @@ class _JetLexer implements FlexLexer {
|
|||||||
*
|
*
|
||||||
* @param errorCode the code of the errormessage to display
|
* @param errorCode the code of the errormessage to display
|
||||||
*/
|
*/
|
||||||
private void zzScanError(int errorCode) {
|
private void zzScanError(int errorCode) throws KotlinLexerException {
|
||||||
String message;
|
String message;
|
||||||
try {
|
try {
|
||||||
message = ZZ_ERROR_MSG[errorCode];
|
message = ZZ_ERROR_MSG[errorCode];
|
||||||
@@ -778,7 +779,7 @@ class _JetLexer implements FlexLexer {
|
|||||||
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(message);
|
throw new KotlinLexerException(message + "\n at '" + yytext() + "'\n" + zzBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -790,7 +791,7 @@ class _JetLexer implements FlexLexer {
|
|||||||
* @param number the number of characters to be read again.
|
* @param number the number of characters to be read again.
|
||||||
* This number must not be greater than yylength()!
|
* This number must not be greater than yylength()!
|
||||||
*/
|
*/
|
||||||
public void yypushback(int number) {
|
public void yypushback(int number) throws KotlinLexerException {
|
||||||
if ( number > yylength() )
|
if ( number > yylength() )
|
||||||
zzScanError(ZZ_PUSHBACK_2BIG);
|
zzScanError(ZZ_PUSHBACK_2BIG);
|
||||||
|
|
||||||
@@ -818,7 +819,7 @@ class _JetLexer implements FlexLexer {
|
|||||||
* @return the next token
|
* @return the next token
|
||||||
* @exception java.io.IOException if any I/O-Error occurs
|
* @exception java.io.IOException if any I/O-Error occurs
|
||||||
*/
|
*/
|
||||||
public IElementType advance() throws java.io.IOException {
|
public IElementType advance() throws java.io.IOException, KotlinLexerException {
|
||||||
int zzInput;
|
int zzInput;
|
||||||
int zzAction;
|
int zzAction;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user