diff --git a/src/main/java/amailp/intellij/robot/elements/RobotTokenTypes.java b/src/main/java/amailp/intellij/robot/elements/RobotTokenTypes.java index f66778e..ee7f547 100644 --- a/src/main/java/amailp/intellij/robot/elements/RobotTokenTypes.java +++ b/src/main/java/amailp/intellij/robot/elements/RobotTokenTypes.java @@ -17,6 +17,7 @@ public interface RobotTokenTypes { final IElementType KeywordsHeader = new RobotIElementType("KeywordsHeader"); final IElementType VariablesHeader = new RobotIElementType("VariablesHeader"); final IElementType TasksHeader = new RobotIElementType("TasksHeader"); + final IElementType CommentsHeader = new RobotIElementType("CommentsHeader"); final IElementType Ellipsis = new RobotIElementType("Ellipsis"); final IElementType ScalarVariable = new RobotIElementType("ScalarVariable"); @@ -35,5 +36,5 @@ public interface RobotTokenTypes { final TokenSet WhitespacesTokens = TokenSet.create(IrrelevantSpaces, BlankLine); final TokenSet CommentsTokens = TokenSet.create(Comment); final TokenSet StringLiteralElements = TokenSet.EMPTY; - final TokenSet HeaderTokens = TokenSet.create(SettingsHeader, TestCasesHeader, KeywordsHeader, VariablesHeader, TasksHeader); + final TokenSet HeaderTokens = TokenSet.create(SettingsHeader, TestCasesHeader, KeywordsHeader, VariablesHeader, TasksHeader, CommentsHeader); } \ No newline at end of file diff --git a/src/main/resources/amailp/intellij/robot/lexer/Robot.flex b/src/main/resources/amailp/intellij/robot/lexer/Robot.flex index 5f876f3..c1fa748 100644 --- a/src/main/resources/amailp/intellij/robot/lexer/Robot.flex +++ b/src/main/resources/amailp/intellij/robot/lexer/Robot.flex @@ -29,6 +29,7 @@ TestCasesHeader = "*** Test Cases ***" | "*** Test Case ***" KeywordsHeader = "*** Keywords ***" | "*** Keyword ***" VariablesHeader = "*** Variables ***" | "*** Variable ***" TasksHeader = "*** Tasks ***" | "*** Task ***" +CommentsHeader = "*** Comments ***" WordChar = [^$@&%\ \t\f\r\n] @@ -68,6 +69,7 @@ EnvironmentVariable = "%{" ~"}" {KeywordsHeader} { yybegin(LINE); return RobotTokenTypes.KeywordsHeader; } {VariablesHeader} { yybegin(LINE); return RobotTokenTypes.VariablesHeader; } {TasksHeader} { yybegin(LINE); return RobotTokenTypes.TasksHeader; } + {CommentsHeader} { yybegin(LINE); return RobotTokenTypes.CommentsHeader;} {Ellipsis} { yybegin(LINE); return RobotTokenTypes.Ellipsis; } {ScalarVariable} { yybegin(LINE); return RobotTokenTypes.ScalarVariable; } diff --git a/src/main/scala/amailp/intellij/robot/ast/package.scala b/src/main/scala/amailp/intellij/robot/ast/package.scala index 0ca4846..974ce98 100644 --- a/src/main/scala/amailp/intellij/robot/ast/package.scala +++ b/src/main/scala/amailp/intellij/robot/ast/package.scala @@ -6,6 +6,7 @@ import com.intellij.psi.tree.TokenSet package object ast { object Tables extends RobotIElementType("Tables") + object CommentsTable extends RobotIElementType("CommentsTable") object SettingsTable extends RobotIElementType("SettingsTable") object Setting extends RobotIElementType("Setting") object SettingName extends RobotIElementType("SettingName") @@ -31,6 +32,5 @@ package object ast { object TableRow extends RobotIElementType("TableRow") object NonEmptyCell extends RobotIElementType("NonEmptyCell") - val tableElementTypes = TokenSet.create(SettingsTable, TestCasesTable, KeywordsTable, VariablesTable) - + val tableElementTypes = TokenSet.create(SettingsTable, TestCasesTable, KeywordsTable, VariablesTable, CommentsTable) } diff --git a/src/main/scala/amailp/intellij/robot/parser/RobotParser.scala b/src/main/scala/amailp/intellij/robot/parser/RobotParser.scala index 497098a..4bcbedd 100644 --- a/src/main/scala/amailp/intellij/robot/parser/RobotParser.scala +++ b/src/main/scala/amailp/intellij/robot/parser/RobotParser.scala @@ -5,6 +5,7 @@ import com.intellij.psi.tree.IElementType import amailp.intellij.robot.elements.RobotTokenTypes._ import amailp.intellij.robot.ast + object RobotParser extends PsiParser { def parse(root: IElementType, builder: PsiBuilder): ASTNode = { val robotBuilder = new RobotPsiBuilder(builder) @@ -17,6 +18,7 @@ object RobotParser extends PsiParser { case TestCasesHeader | TasksHeader => parseTableItemsWith(parseTestCaseDefinition); Some(ast.TestCasesTable) case KeywordsHeader => parseTableItemsWith(parseKeywordDefinition); Some(ast.KeywordsTable) case VariablesHeader => parseTableItemsWith(parseVariableDefinition); Some(ast.VariablesTable) + case CommentsHeader => parseTableItemsWith(parseCommentsTable); Some(ast.CommentsTable) case _ => None } tableType match { @@ -25,6 +27,13 @@ object RobotParser extends PsiParser { } } + def parseCommentsTable(): Unit = { + while (!isHeader(currentType)) { + //val comments_line = currentText + advanceLexer() + } + } + def parseHeaderRow(): IElementType = { val headerMark = mark val headerType = currentType diff --git a/src/main/scala/amailp/intellij/robot/parser/package.scala b/src/main/scala/amailp/intellij/robot/parser/package.scala index 2ba7331..b581cd9 100644 --- a/src/main/scala/amailp/intellij/robot/parser/package.scala +++ b/src/main/scala/amailp/intellij/robot/parser/package.scala @@ -18,6 +18,12 @@ package object parser { def currentType = getTokenType def currentText = getTokenText + def parserCommentLine(includingTerminator: Boolean = true): Unit = { + while (currentType != SettingsHeader) { + parseRowContent() + } + } + def parseRowContent(includingTerminator: Boolean = true) { if (!currentIsSeparator) parseCellOfType(ast.NonEmptyCell) parseRemainingCells() diff --git a/src/test/resources/CommentsTableTest/CommentsTableKeywords.robot b/src/test/resources/CommentsTableTest/CommentsTableKeywords.robot new file mode 100644 index 0000000..5c087b9 --- /dev/null +++ b/src/test/resources/CommentsTableTest/CommentsTableKeywords.robot @@ -0,0 +1,3 @@ +*** Comments *** +Hello World +*** Keywords *** \ No newline at end of file diff --git a/src/test/resources/CommentsTableTest/CommentsTableSettings.robot b/src/test/resources/CommentsTableTest/CommentsTableSettings.robot new file mode 100644 index 0000000..0bce497 --- /dev/null +++ b/src/test/resources/CommentsTableTest/CommentsTableSettings.robot @@ -0,0 +1,3 @@ +*** Comments *** +Hello World +*** Settings *** \ No newline at end of file diff --git a/src/test/resources/CommentsTableTest/CommentsTableTasks.robot b/src/test/resources/CommentsTableTest/CommentsTableTasks.robot new file mode 100644 index 0000000..9a8a028 --- /dev/null +++ b/src/test/resources/CommentsTableTest/CommentsTableTasks.robot @@ -0,0 +1,3 @@ +*** Comments *** +Hello World +*** Tasks *** \ No newline at end of file diff --git a/src/test/resources/CommentsTableTest/CommentsTableTestCases.robot b/src/test/resources/CommentsTableTest/CommentsTableTestCases.robot new file mode 100644 index 0000000..ed6d4d6 --- /dev/null +++ b/src/test/resources/CommentsTableTest/CommentsTableTestCases.robot @@ -0,0 +1,3 @@ +*** Comments *** +Hello World +*** Test Cases *** diff --git a/src/test/resources/CommentsTableTest/CommentsTableVariables.robot b/src/test/resources/CommentsTableTest/CommentsTableVariables.robot new file mode 100644 index 0000000..50df9fc --- /dev/null +++ b/src/test/resources/CommentsTableTest/CommentsTableVariables.robot @@ -0,0 +1,3 @@ +*** Comments *** +Hello World +*** Variables *** \ No newline at end of file diff --git a/src/test/scala/amailp/intellij/robot/psi/tables/RobotCommentsTableTest.scala b/src/test/scala/amailp/intellij/robot/psi/tables/RobotCommentsTableTest.scala new file mode 100644 index 0000000..ec10cde --- /dev/null +++ b/src/test/scala/amailp/intellij/robot/psi/tables/RobotCommentsTableTest.scala @@ -0,0 +1,31 @@ +package amailp.intellij.robot.psi.tables + +import amailp.intellij.robot.psi.RobotPsiFile +import amailp.intellij.robot.structureView.RobotTreeBasedStructureViewBuilder +import amailp.intellij.robot.testFramework.RobotCodeInsightFixtureTestCase + +class RobotCommentsTableTest extends RobotCodeInsightFixtureTestCase { + + def testCommentsSetting(): Unit = { + val files = myFixture + .configureByFiles( + "CommentsTableTest/CommentsTableSettings.robot" + ) + .map(_.asInstanceOf[RobotPsiFile]) + + val oneComments = files.head + + val structureViewModel = + new RobotTreeBasedStructureViewBuilder(oneComments).createStructureViewModel(myFixture.getEditor) + + val root = structureViewModel.getRoot + root.getChildren should have size 1 + + + val comments = root.getChildren()(0) + val settings = root.getChildren()(1) + + comments.getPresentation.getPresentableText should equal("Comments") + settings.getPresentation.getPresentableText should equal("Settings") + } +} diff --git a/src/test/scala/amailp/intellij/robot/testFramework/RobotCodeInsightFixtureTestCase.scala b/src/test/scala/amailp/intellij/robot/testFramework/RobotCodeInsightFixtureTestCase.scala index 3426c57..88f077d 100644 --- a/src/test/scala/amailp/intellij/robot/testFramework/RobotCodeInsightFixtureTestCase.scala +++ b/src/test/scala/amailp/intellij/robot/testFramework/RobotCodeInsightFixtureTestCase.scala @@ -11,10 +11,7 @@ import org.scalatest.matchers.should.Matchers import org.scalatestplus.junit.AssertionsForJUnit @Ignore -class RobotCodeInsightFixtureTestCase - extends BasePlatformTestCase - with Matchers - with AssertionsForJUnit { +class RobotCodeInsightFixtureTestCase extends BasePlatformTestCase with Matchers with AssertionsForJUnit { override def getTestDataPath = new File(this.getClass.getClassLoader.getResource("complete.robot").toURI).getParent