Skip to content

Commit 9259ff6

Browse files
authored
Merge pull request #157 from Krzmbrzl/parser-rewrite
Parser rewrite + 0.7.5
2 parents ae40568 + 743a423 commit 9259ff6

File tree

562 files changed

+41003
-35594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

562 files changed

+41003
-35594
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
45+
# java class files
46+
plugin/*/bin/

plugin/Raven.SQDev.Editors/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Editors
44
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
5-
Bundle-Version: 0.7.1.stable
5+
Bundle-Version: 0.7.2.stable
66
Bundle-Activator: raven.sqdev.editors.activator.Activator
77
Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.runtime,
9-
org.eclipse.ui.editors;bundle-version="3.8.200",
10-
org.eclipse.jface.text;bundle-version="3.9.2",
9+
org.eclipse.ui.editors,
10+
org.eclipse.jface.text,
1111
org.eclipse.swt,
1212
org.eclipse.core.resources,
1313
org.eclipse.ui.ide,
14-
org.eclipse.core.filesystem;bundle-version="1.4.100",
15-
raven.sqdev.misc;bundle-version="0.6.0"
14+
org.eclipse.core.filesystem,
15+
raven.sqdev.misc
1616
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1717
Bundle-ActivationPolicy: lazy
1818
Export-Package: raven.sqdev.editors;
@@ -42,6 +42,5 @@ Import-Package: raven.sqdev.constants,
4242
raven.sqdev.parser.misc,
4343
raven.sqdev.parser.preprocessor,
4444
raven.sqdev.pluginManagement,
45-
raven.sqdev.pluginManager,
4645
raven.sqdev.sqdevFile,
4746
raven.sqdev.util
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/stringtableParsing/StringTable.tokens

-19
This file was deleted.

plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/stringtableParsing/StringTableLexer.tokens

-19
This file was deleted.

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java

+58-51
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package raven.sqdev.editors;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.IOException;
5+
import java.io.InputStream;
36
import java.util.AbstractMap;
47
import java.util.ArrayList;
58
import java.util.List;
9+
import java.util.stream.Collectors;
610

711
import org.antlr.v4.runtime.tree.ParseTree;
812
import org.eclipse.core.resources.IMarker;
@@ -37,6 +41,7 @@
3741
import raven.sqdev.interfaces.IMacroSupport;
3842
import raven.sqdev.interfaces.IManager;
3943
import raven.sqdev.interfaces.IMarkerSupport;
44+
import raven.sqdev.interfaces.IParseResult;
4045
import raven.sqdev.misc.CharacterPair;
4146
import raven.sqdev.misc.MultiPreferenceStore;
4247
import raven.sqdev.misc.SQDevInfobox;
@@ -80,9 +85,9 @@ public class BasicCodeEditor extends TextEditor implements IMarkerSupport {
8085
protected BasicSourceViewerConfiguration configuration;
8186

8287
/**
83-
* The parse tree representing the input of this editor
88+
* The parse result representing the input of this editor
8489
*/
85-
protected ParseTree parseTree;
90+
protected IParseResult parseResult;
8691
/**
8792
* The name of the rules used for parsing this editor's input
8893
*/
@@ -142,8 +147,8 @@ public void setColorManager(ColorManager colorManager) {
142147

143148
@Override
144149
public ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
145-
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(),
146-
isOverviewRulerVisible(), styles);
150+
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(),
151+
styles);
147152

148153
getSourceViewerDecorationSupport(viewer);
149154

@@ -158,8 +163,7 @@ public ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler,
158163
}
159164

160165
// add parse listener
161-
getBasicProvider().getDocument(getEditorInput())
162-
.addDocumentListener(new BasicParseTimeListener(this));
166+
getBasicProvider().getDocument(getEditorInput()).addDocumentListener(new BasicParseTimeListener(this));
163167

164168
return viewer;
165169
}
@@ -175,13 +179,11 @@ protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupp
175179

176180
// character pair matching
177181
support.setCharacterPairMatcher(matcher);
178-
support.setMatchingCharacterPainterPreferenceKeys(
179-
SQDevPreferenceConstants.SQDEV_EDITOR_MATCHING_BRACKETS_KEY,
182+
support.setMatchingCharacterPainterPreferenceKeys(SQDevPreferenceConstants.SQDEV_EDITOR_MATCHING_BRACKETS_KEY,
180183
SQDevPreferenceConstants.SQDEV_EDITOR_MATCHING_BRACKETS_COLOR_KEY);
181184

182185
// newLine highlighting
183-
support.setCursorLinePainterPreferenceKeys(
184-
SQDevPreferenceConstants.SQDEV_EDITOR_HIGHLIGHT_CURRENTLINE_KEY,
186+
support.setCursorLinePainterPreferenceKeys(SQDevPreferenceConstants.SQDEV_EDITOR_HIGHLIGHT_CURRENTLINE_KEY,
185187
SQDevPreferenceConstants.SQDEV_EDITOR_HIGHLIGHT_CURRENTLINE_COLOR_KEY);
186188

187189
}
@@ -253,8 +255,7 @@ public void createPartControl(Composite parent) {
253255
// infrastructure for code folding
254256
ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
255257

256-
ProjectionSupport projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(),
257-
getSharedColors());
258+
ProjectionSupport projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
258259

259260
projectionSupport.install();
260261

@@ -266,8 +267,7 @@ public void createPartControl(Composite parent) {
266267
// combine the SQDev PreferenceStore with the editor's one
267268

268269
// use the SQDev preferenceStore as the baseStore
269-
MultiPreferenceStore multiStore = new MultiPreferenceStore(
270-
SQDevPreferenceUtil.getPreferenceStore());
270+
MultiPreferenceStore multiStore = new MultiPreferenceStore(SQDevPreferenceUtil.getPreferenceStore());
271271

272272
// add the editor's preferenceStore if available
273273
IPreferenceStore editorStore = this.getPreferenceStore();
@@ -341,13 +341,13 @@ public BasicDocumentProvider getBasicProvider() {
341341
}
342342

343343
/**
344-
* Gets the <code>ParseTree</code> representing the input of this editor
344+
* Gets the {@linkplain IParseResult} representing the input of this editor
345345
*
346-
* @return The <code>ParseTree</code> or <code>null</code> if none has been set
346+
* @return The result or <code>null</code> if none has been set
347347
* so far
348348
*/
349-
public ParseTree getParseTree() {
350-
return parseTree;
349+
public IParseResult getParseResult() {
350+
return parseResult;
351351
}
352352

353353
/**
@@ -360,8 +360,8 @@ public List<String> getParseRuleNames() {
360360
}
361361

362362
/**
363-
* This is a helper method that will do the parsing for the given input wihtout
364-
* any checks (whetehr there is an active parsing job) and in the same thread as
363+
* This is a helper method that will do the parsing for the given input without
364+
* any checks (whether there is an active parsing job) and in the same thread as
365365
* it is called
366366
*
367367
* @param input
@@ -370,7 +370,7 @@ public List<String> getParseRuleNames() {
370370
*/
371371
private IStatus startParsingInput(String input) {
372372
// preprocess
373-
doPreprocessorParsing(input);
373+
doPreprocessorParsing(new ByteArrayInputStream(input.getBytes()));
374374

375375
// check if this parsing should be cancelled
376376
synchronized (parsingIsCancelled) {
@@ -381,7 +381,7 @@ private IStatus startParsingInput(String input) {
381381
}
382382

383383
// parse
384-
ParseTree output = doParse(input);
384+
IParseResult output = doParse(new ByteArrayInputStream(input.getBytes()));
385385

386386
// check if this parsing should be cancelled
387387
synchronized (parsingIsCancelled) {
@@ -391,14 +391,17 @@ private IStatus startParsingInput(String input) {
391391
}
392392
}
393393

394-
if (output == null || output.getChildCount() == 0) {
394+
if (output == null
395+
|| output.getMarkers().stream().filter((element) -> element.getSeverity() == IMarker.SEVERITY_ERROR)
396+
.collect(Collectors.toList()).size() > 0) {
397+
// don't process the parse tree if errors came up during lexing/parsing
395398
applyParseChanges();
396399

397400
return Status.CANCEL_STATUS;
398401
} else {
399-
parseTree = output;
402+
parseResult = output;
400403

401-
if (!processParseTree(parseTree)) {
404+
if (!processParseTree(parseResult)) {
402405
applyParseChanges();
403406
}
404407

@@ -433,30 +436,29 @@ public boolean parseInput(boolean suspend) {
433436
return false;
434437
}
435438

436-
String input = document.get();
439+
String content = document.get();
437440

438-
if (input == null) {
441+
if (content == null) {
439442
return false;
440443
}
441444

442445
synchronized (parsingIsCancelled) {
443446
if (parsingIsCancelled && (parseJob == null || parseJob.getResult() != null)) {
444447
// There is no other parsing in progress that should be
445-
// cancelled and cancelling is only possible after having
448+
// cancelled and canceling is only possible after having
446449
// initialized it
447450
parsingIsCancelled = false;
448451
}
449452
}
450453

451454
if (parseJob != null && parseJob.getState() != Job.NONE) {
452-
// Ther previous Job is still running -> reschedule
455+
// The previous Job is still running -> reschedule
453456
parseJob.addJobChangeListener(new JobChangeAdapter() {
454457

455458
@Override
456459
public void done(IJobChangeEvent event) {
457460
// As there has been a request to parse the input again
458-
// do
459-
// it now as the old parsing process is finished
461+
// do it now as the old parsing process is finished
460462
parseInput();
461463
}
462464
});
@@ -465,13 +467,13 @@ public void done(IJobChangeEvent event) {
465467
}
466468

467469
if (suspend) {
468-
startParsingInput(input);
470+
startParsingInput(content);
469471
} else {
470472
parseJob = new Job("Parsing \"" + getEditorInput().getName() + "\"...") {
471473

472474
@Override
473475
protected IStatus run(IProgressMonitor monitor) {
474-
return startParsingInput(input);
476+
return startParsingInput(content);
475477
}
476478
};
477479

@@ -514,10 +516,17 @@ public void cancelParsing() {
514516
* and sets the found macros if this editor is an instance of
515517
* <code>IMacroSupport</code>.
516518
*/
517-
protected void doPreprocessorParsing(String input) {
519+
protected void doPreprocessorParsing(InputStream input) {
518520
if (this instanceof IMacroSupport && getEditorInput() instanceof IFileEditorInput) {
519-
PreprocessorParseResult result = ParseUtil.parseAndValidatePreprocess(input,
520-
((IFileEditorInput) getEditorInput()).getFile().getLocation());
521+
PreprocessorParseResult result;
522+
try {
523+
result = ParseUtil.parseAndValidatePreprocess(input,
524+
((IFileEditorInput) getEditorInput()).getFile().getLocation());
525+
} catch (IOException e) {
526+
e.printStackTrace();
527+
createMarker(IMarker.PROBLEM, 0, 0, "Unable to preprocess the file", IMarker.SEVERITY_ERROR);
528+
return;
529+
}
521530

522531
((IMacroSupport) this).setMacros(result.getMacros(), true);
523532

@@ -533,18 +542,18 @@ protected void doPreprocessorParsing(String input) {
533542
* Note: You might want to call {@link #applyParseChanges()} after the
534543
* processing
535544
*
536-
* @param tree
537-
* The generated tree
545+
* @param parseResult
546+
* The generated parse result
538547
* @return Whether this function has called {@link #applyParseChanges()}. If not
539548
* the default implementation of {@link #parseInput()} will call this
540549
* function afterwards.
541550
*/
542-
protected boolean processParseTree(ParseTree parseTree) {
551+
protected boolean processParseTree(IParseResult parseResult) {
543552
return false;
544553
}
545554

546555
/**
547-
* Parses the input of this editor in order to set the {@link #parseTree} for
556+
* Parses the input of this editor in order to set the {@link #parseResult} for
548557
* this editor. <br>
549558
* Note: You might want to call {@link #applyParseChanges()} after parsing (or
550559
* rather after {@link #processParseTree(ParseTree)}.<br>
@@ -559,7 +568,7 @@ protected boolean processParseTree(ParseTree parseTree) {
559568
* parsing failed (if not overridden by subclasses this method always
560569
* returns <code>null</code>
561570
*/
562-
protected ParseTree doParse(String input) {
571+
protected IParseResult doParse(InputStream input) {
563572
// parsing diabled
564573
return null;
565574
}
@@ -573,8 +582,7 @@ protected ParseTree doParse(String input) {
573582
*/
574583
protected void createManagers(List<IManager> managerList) {
575584
// add folding manager
576-
managerList.add(new BasicFoldingManager(
577-
((ProjectionViewer) getSourceViewer()).getProjectionAnnotationModel()));
585+
managerList.add(new BasicFoldingManager(((ProjectionViewer) getSourceViewer()).getProjectionAnnotationModel()));
578586
// add marker manager
579587
managerList.add(new BasicMarkerManager(this));
580588
}
@@ -598,8 +606,8 @@ public void createMarker(String type, int offset, int length, String message, in
598606
}
599607
}
600608

601-
((BasicMarkerManager) getManager(BasicMarkerManager.TYPE)).addMarker(type, line, offset, length,
602-
severity, message);
609+
((BasicMarkerManager) getManager(BasicMarkerManager.TYPE)).addMarker(type, line, offset, length, severity,
610+
message);
603611
}
604612

605613
@Override
@@ -651,8 +659,8 @@ public void addFoldingArea(Position position) {
651659

652660
// don't fold if the code is only one line long
653661
try {
654-
if (doc == null || doc.getLineOfOffset(position.offset) == doc
655-
.getLineOfOffset(position.offset + position.length)) {
662+
if (doc == null
663+
|| doc.getLineOfOffset(position.offset) == doc.getLineOfOffset(position.offset + position.length)) {
656664
return;
657665
}
658666
} catch (BadLocationException e) {
@@ -666,15 +674,14 @@ public void addFoldingArea(Position position) {
666674

667675
ProjectionAnnotation annotation = new ProjectionAnnotation();
668676

669-
BasicFoldingManager foldingManager = (BasicFoldingManager) getManager(
670-
BasicFoldingManager.getManagerType());
677+
BasicFoldingManager foldingManager = (BasicFoldingManager) getManager(BasicFoldingManager.getManagerType());
671678

672679
if (foldingManager == null) {
673680
return;
674681
}
675682

676-
foldingManager.addFoldingArea(
677-
new AbstractMap.SimpleEntry<ProjectionAnnotation, Position>(annotation, position));
683+
foldingManager
684+
.addFoldingArea(new AbstractMap.SimpleEntry<ProjectionAnnotation, Position>(annotation, position));
678685
}
679686

680687
/**

0 commit comments

Comments
 (0)