Added Language settings page with one option so far (-spaces option). Fixed lexer without -spaces option and directives.

This commit is contained in:
2021-10-09 16:56:06 +02:00
parent 031d5ff4ab
commit 0ae17046d6
12 changed files with 280 additions and 174 deletions
@@ -2,6 +2,7 @@ package de.platon42.intellij.jupiter;
import com.intellij.lang.ParserDefinition;
import com.intellij.mock.MockProjectEx;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.PsiFile;
@@ -113,6 +114,8 @@ public class ParsingTestExtension implements ParameterResolver, AfterTestExecuti
public interface IParsingTestCase {
MockProjectEx getProject();
ParserDefinition getParserDefinition();
void ensureNoErrorElements();
@@ -3,6 +3,7 @@ package de.platon42.intellij.plugins.m68k.parser
import de.platon42.intellij.jupiter.MyTestCase
import de.platon42.intellij.jupiter.ParsingTestExtension
import de.platon42.intellij.jupiter.TestDataSubPath
import de.platon42.intellij.plugins.m68k.settings.M68kProjectSettings
import org.junit.jupiter.api.Test
@TestDataSubPath("comments")
@@ -50,37 +51,51 @@ internal class CommentsTest : AbstractParsingTest() {
@Test
internal fun comment_after_instruction_with_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = true
setSpacesSetting(testCase, true)
testGoodSyntax(testCase, " add.w d0,d0 hey comment\n")
}
@Test
internal fun comment_after_assignment_with_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = true
setSpacesSetting(testCase, true)
testGoodSyntax(testCase, "FOO = 123+23 hey comment\n")
}
@Test
internal fun comment_after_data_directive_with_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
setSpacesSetting(testCase, true)
testGoodSyntax(testCase, " dc.w $1234,$2345 hey comment\n")
}
@Test
internal fun comment_after_macro_call_with_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = true
setSpacesSetting(testCase, true)
testGoodSyntax(testCase, " PUSHM d0,d0 hey comment\n")
}
@Test
internal fun space_does_not_start_comment_within_instruction_without_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = false
setSpacesSetting(testCase, false)
testGoodSyntax(testCase, " add.w # 234, d0 ; hey comment\n")
}
@Test
internal fun space_does_not_start_comment_within_assignment_without_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = false
setSpacesSetting(testCase, false)
testGoodSyntax(testCase, "FOO = 123 + 23 ; hey comment\n")
}
@Test
internal fun space_does_not_start_comment_within_macro_call_without_space_introduces_comment_option(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
(testCase.parserDefinition as M68kParserDefinition).lexerPrefs.spaceIntroducesComment = false
setSpacesSetting(testCase, false)
testGoodSyntax(testCase, " PUSHM d0, d0 ; hey comment\n")
}
private fun setSpacesSetting(testCase: ParsingTestExtension.IParsingTestCase, spacesOption: Boolean) {
val settings = M68kProjectSettings()
settings.settings.spaceIntroducesComment = spacesOption
testCase.project.registerService(M68kProjectSettings::class.java, settings)
}
}
@@ -0,0 +1,15 @@
Assembly File: a.asm
PsiWhiteSpace(' ')
M68kStatementImpl(STATEMENT)
M68kPreprocessorDirectiveImpl(PREPROCESSOR_DIRECTIVE)
M68kPreprocessorKeywordImpl(PREPROCESSOR_KEYWORD)
PsiElement(M68kTokenType.DATA_DIRECTIVE)('dc.w')
PsiWhiteSpace(' ')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.HEXADECIMAL)('$1234')
PsiElement(M68kTokenType.SEPARATOR)(',')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.HEXADECIMAL)('$2345')
PsiWhiteSpace(' ')
PsiComment(M68kTokenType.COMMENT)('hey comment')
PsiElement(M68kTokenType.EOL)('\n')