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
@@ -118,9 +118,9 @@ PLAIN_MACRO_LINE=[^;\r\n]+
if(isAsmMnemonicWithSize(yytext())) { yybegin(ASMINSTR); yypushback(2); return MNEMONIC; }
if(isAsmMnemonic(yytext())) { yybegin(ASMINSTR); return MNEMONIC; }
//if(isEndDirective(yytext())) { yybegin(YYINITIAL); zzAtEOF = true; return null; }
if(isDataDirective(yytext())) { startExpr(EXPR, EXPR_OP); return DATA_DIRECTIVE; }
if(isPlainDirective(yytext())) { yybegin(PLAINPARAMS); return OTHER_DIRECTIVE; }
if(isOtherDirective(yytext())) { startExpr(EXPR, EXPR_OP); return OTHER_DIRECTIVE; }
if(isDataDirective(yytext())) { eatOneWhitespace = true; startExpr(EXPR, EXPR_OP); return DATA_DIRECTIVE; }
if(isPlainDirective(yytext())) { eatOneWhitespace = true; yybegin(PLAINPARAMS); return OTHER_DIRECTIVE; }
if(isOtherDirective(yytext())) { eatOneWhitespace = true; startExpr(EXPR, EXPR_OP); return OTHER_DIRECTIVE; }
return handleMacroMode(this);
}
{MACRONAME} { return handleMacroMode(this); }
@@ -10,15 +10,14 @@ import de.platon42.intellij.plugins.m68k.lexer.M68kLexer
import de.platon42.intellij.plugins.m68k.lexer.M68kLexerPrefs
import de.platon42.intellij.plugins.m68k.psi.M68kFile
import de.platon42.intellij.plugins.m68k.psi.M68kTypes
import de.platon42.intellij.plugins.m68k.settings.M68kProjectSettings
import de.platon42.intellij.plugins.m68k.stubs.M68kElementTypes
class M68kParserDefinition : ParserDefinition {
val lexerPrefs = M68kLexerPrefs() // TODO make this configurable
override fun createLexer(project: Project): Lexer {
// TODO take prefs from project somehow
return M68kLexer(lexerPrefs)
val settings = project.getService(M68kProjectSettings::class.java)
return M68kLexer(settings?.settings ?: M68kLexerPrefs())
}
override fun createParser(project: Project) = M68kParser()
@@ -0,0 +1,19 @@
package de.platon42.intellij.plugins.m68k.settings
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.components.StoragePathMacros
import de.platon42.intellij.plugins.m68k.lexer.M68kLexerPrefs
@State(name = "M68k.Settings", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)])
class M68kProjectSettings : PersistentStateComponent<M68kLexerPrefs> {
var settings: M68kLexerPrefs = M68kLexerPrefs()
override fun getState() = settings
override fun loadState(state: M68kLexerPrefs) {
settings = state
}
}
@@ -0,0 +1,45 @@
package de.platon42.intellij.plugins.m68k.settings
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsContexts.ConfigurableName
import com.intellij.ui.components.JBCheckBox
import com.intellij.uiDesigner.core.Spacer
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UIUtil
import de.platon42.intellij.plugins.m68k.lexer.M68kLexerPrefs
import javax.swing.JComponent
class M68kProjectSettingsConfigurable(project: Project?) : Configurable {
private val settings = project?.getService(M68kProjectSettings::class.java)
private val spacesOptionField = JBCheckBox("Space introduces comment (-spaces)", settings?.settings?.spaceIntroducesComment ?: false)
override fun getDisplayName(): @ConfigurableName String = "M68k"
override fun createComponent(): JComponent? {
return FormBuilder.createFormBuilder()
.setAlignLabelOnRight(false)
.setHorizontalGap(UIUtil.DEFAULT_HGAP)
.setVerticalGap(UIUtil.DEFAULT_VGAP)
.addComponent(spacesOptionField)
.addComponentFillVertically(Spacer(), 0)
.panel
}
override fun isModified(): Boolean {
return settings?.settings?.spaceIntroducesComment != spacesOptionField.isSelected
}
@Throws(ConfigurationException::class)
override fun apply() {
settings?.settings?.spaceIntroducesComment = spacesOptionField.isSelected
}
override fun reset() {
val default = M68kLexerPrefs()
settings?.settings?.spaceIntroducesComment = default.spaceIntroducesComment
}
}
@@ -11,15 +11,13 @@ import com.intellij.psi.tree.IElementType
import de.platon42.intellij.plugins.m68k.lexer.M68kLexer
import de.platon42.intellij.plugins.m68k.lexer.M68kLexerPrefs
import de.platon42.intellij.plugins.m68k.psi.M68kTypes
import de.platon42.intellij.plugins.m68k.settings.M68kProjectSettings
class M68kSyntaxHighlighter(val project: Project?) : SyntaxHighlighterBase() {
private val settings = project?.getService(M68kProjectSettings::class.java)
override fun getHighlightingLexer(): Lexer {
if (project == null) {
return M68kLexer(M68kLexerPrefs()) // Use some defaults
} else {
// FIXME Where do we get the prefs from?
return M68kLexer(M68kLexerPrefs())
}
return M68kLexer(settings?.settings ?: M68kLexerPrefs()) // Use some defaults
}
override fun getTokenHighlights(tokenType: IElementType): Array<TextAttributesKey> {