-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
148 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
dev.thihup.jvisualg.ide/src/main/java/dev/thihup/jvisualg/ide/ReplaceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.thihup.jvisualg.ide; | ||
|
||
import org.fife.rsta.ui.search.SearchEvent; | ||
import org.fife.rsta.ui.search.SearchListener; | ||
import org.fife.ui.rtextarea.RTextArea; | ||
import org.fife.ui.rtextarea.SearchContext; | ||
import org.fife.ui.rtextarea.SearchEngine; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.function.Supplier; | ||
|
||
class ReplaceListener implements SearchListener { | ||
private final RTextArea textArea; | ||
private final Supplier<SearchContext[]> searchContext; | ||
|
||
public ReplaceListener(RTextArea textArea, Supplier<SearchContext[]> searchContext) { | ||
this.textArea = textArea; | ||
this.searchContext = searchContext; | ||
} | ||
|
||
@Override | ||
public void searchEvent(SearchEvent searchEvent) { | ||
switch (searchEvent.getType()) { | ||
case FIND -> SearchEngine.find(textArea, searchContext.get()[0]); | ||
case REPLACE -> SearchEngine.replace(textArea, searchContext.get()[0]); | ||
case REPLACE_ALL -> SearchEngine.replaceAll(textArea, searchContext.get()[0]); | ||
case MARK_ALL -> SearchEngine.markAll(textArea, searchContext.get()[0]); | ||
} | ||
} | ||
|
||
@Override | ||
public String getSelectedText() { | ||
return textArea.getSelectedText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dev.thihup.jvisualg.ide/src/main/java/dev/thihup/jvisualg/ide/TypeChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dev.thihup.jvisualg.ide; | ||
|
||
import dev.thihup.jvisualg.frontend.ASTResult; | ||
import dev.thihup.jvisualg.frontend.Error; | ||
import dev.thihup.jvisualg.frontend.TypeCheckerResult; | ||
import dev.thihup.jvisualg.frontend.VisualgParser; | ||
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; | ||
import org.fife.ui.rsyntaxtextarea.parser.AbstractParser; | ||
import org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult; | ||
import org.fife.ui.rsyntaxtextarea.parser.DefaultParserNotice; | ||
import org.fife.ui.rsyntaxtextarea.parser.ParseResult; | ||
|
||
import java.util.List; | ||
|
||
class TypeChecker extends AbstractParser { | ||
@Override | ||
public ParseResult parse(RSyntaxDocument doc, String style) { | ||
DefaultParseResult parseResult = new DefaultParseResult(this); | ||
long start = System.currentTimeMillis(); | ||
parseResult.setParsedLines(0, doc.getDefaultRootElement().getElementCount()); | ||
|
||
try { | ||
String text = doc.getText(0, doc.getLength()); | ||
ASTResult astResult = VisualgParser.parse(text); | ||
|
||
List<Error> errors = astResult.errors(); | ||
|
||
astResult.node() | ||
.map(dev.thihup.jvisualg.frontend.TypeChecker::semanticAnalysis) | ||
.map(TypeCheckerResult::errors) | ||
.ifPresent(errors::addAll); | ||
|
||
errors.stream() | ||
.map(x -> { | ||
int offset = doc.getTokenListForLine(x.location().startLine() - 1).getOffset(); | ||
return new DefaultParserNotice(this, x.message(), x.location().startLine() - 1, offset + x.location().startColumn(), x.location().endColumn() - x.location().startColumn() + 1); | ||
}) | ||
.forEach(parseResult::addNotice); | ||
} catch (Exception e) { | ||
parseResult.setError(e); | ||
} | ||
parseResult.setParseTime(System.currentTimeMillis() - start); | ||
return parseResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.