From 4dac7171d72c9440d62998313f1f10df96136aa0 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 16 May 2019 11:50:17 -0700 Subject: [PATCH] [ agda ] Fix AST creation --- src/org/ice1000/tt/psi/agda/parser.kt | 3 ++- src/org/ice1000/tt/psi/layout.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/ice1000/tt/psi/agda/parser.kt b/src/org/ice1000/tt/psi/agda/parser.kt index 5e7c84f..85f3416 100644 --- a/src/org/ice1000/tt/psi/agda/parser.kt +++ b/src/org/ice1000/tt/psi/agda/parser.kt @@ -36,7 +36,8 @@ class AgdaTokenType(debugName: String) : IElementType(debugName, AgdaLanguage.IN @JvmField val IDENTIFIERS = TokenSet.create(AgdaTypes.IDENTIFIER) fun fromText(text: String, project: Project) = PsiFileFactory.getInstance(project).createFileFromText(AgdaLanguage.INSTANCE, text)?.firstChild - fun createSignature(text: String, project: Project) = fromText(text, project) as? AgdaSignature + fun createLayout(text: String, project: Project) = fromText(text, project) as? AgdaLayout + fun createSignature(text: String, project: Project) = createLayout(text, project)?.firstChild as? AgdaSignature fun createExp(text: String, project: Project) = createSignature("f : $text", project)?.exp fun createStr(text: String, project: Project) = createExp(text, project) as? AgdaString } diff --git a/src/org/ice1000/tt/psi/layout.kt b/src/org/ice1000/tt/psi/layout.kt index f247392..2d7671a 100644 --- a/src/org/ice1000/tt/psi/layout.kt +++ b/src/org/ice1000/tt/psi/layout.kt @@ -113,7 +113,7 @@ class LayoutLexer( when (state) { WaitingForLayout -> { if (token.isCode && token.column > indentStack.peek()) { - tokens.add(i, virtualToken(layoutStart, tokens[i - 1])) + tokens.add(i, virtualToken(layoutStart, tokens[(i - 1).coerceAtLeast(0)])) i++ indentStack.push(token.column) if (token.elementType !in layoutCreatingTokens) state = Normal