blob: 67502632f7ea817c890c6ab5ea37c6e1c4ae4c79 [file] [log] [blame]
<project name="KotlinLexer" default="lexer">
<property name="home" value="${basedir}"/>
<property name="builddir" value="${basedir}/build"/>
<property name="flex.classpath" value=""/>
<property name="out.dir" value="${builddir}/tmpout"/>
<!-- TODO: KT-77206 (Get rid of the skeleton downloading or use JFlex version instead of the commit hash) -->
<property name="skeleton.version" value="486d14622bd240ceccd844a0e65d7c69e7e44735" />
<property name="skeleton.download.path" value="${builddir}/idea-flex-${skeleton.version}.skeleton" />
<macrodef name="flex">
<attribute name="flexfile"/>
<attribute name="destdir"/>
<attribute name="skeleton" default="${skeleton.download.path}"/>
<sequential>
<delete dir="${out.dir}"/>
<mkdir dir="${out.dir}"/>
<java classname="jflex.Main"
jvmargs="-Xmx512M"
fork="true"
failonerror="true">
<arg value="-skel"/>
<arg value="@{skeleton}"/>
<arg value="-d"/>
<arg value="${out.dir}"/>
<arg value="@{flexfile}"/>
<classpath>
<pathelement path="${flex.classpath}"/>
</classpath>
</java>
<move todir="@{destdir}">
<fileset dir="${out.dir}">
<include name="*.java"/>
</fileset>
</move>
<delete dir="${out.dir}"/>
</sequential>
</macrodef>
<target name="check-idea-flex.skeleton.exists">
<available file="${skeleton.download.path}" property="skeleton.exists"/>
</target>
<target name="get-idea-flex.skeleton.if.not.exists" depends="check-idea-flex.skeleton.exists" unless="skeleton.exists">
<get src="https://raw.githubusercontent.com/JetBrains/intellij-community/${skeleton.version}/tools/lexer/idea-flex.skeleton"
dest="${skeleton.download.path}" usetimestamp="true"/>
</target>
<target name="lexer" depends="get-idea-flex.skeleton.if.not.exists">
<flex flexfile="${home}/src/org/jetbrains/kotlin/lexer/Kotlin.flex"
destdir="${home}/src/org/jetbrains/kotlin/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/kotlin/lexer/_JetLexer.java"
match="throw new KotlinLexerException\(message\);"
replace="throw new KotlinLexerException(message + &quot;\\\\n at '&quot; + yytext() + &quot;'\\\\n&quot; + zzBuffer);"/>
<flex flexfile="${home}/src/org/jetbrains/kotlin/kdoc/lexer/KDoc.flex"
destdir="${home}/src/org/jetbrains/kotlin/kdoc/lexer/"/>
</target>
</project>