Skip to content

Commit

Permalink
Verificação básica de erros
Browse files Browse the repository at this point in the history
  • Loading branch information
dgadelha committed Sep 2, 2023
1 parent 26516a0 commit f7b5a83
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
"@angular/router": "^16.2.0",
"@materia-ui/ngx-monaco-editor": "^6.0.0",
"@portugol-webstudio/antlr": "*",
"@portugol-webstudio/parser": "*",
"@portugol-webstudio/resources": "*",
"@portugol-webstudio/runner": "*",
"@portugol-webstudio/runtime": "*",
"@sentry/angular-ivy": "^7.62.0",
"angular-split": "^15.0.0",
"angular-svg-icon": "^16.0.0",
"antlr4ts": "^0.5.0-alpha.4",
"assert": "^2.0.0",
"file-saver": "^2.0.5",
"firebase": "^9.23.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/ide/src/app/tab-editor/tab-editor.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
height: 100%;
}

::ng-deep .editor-inner {
.monaco-editor .monaco-hover {
position: fixed;
z-index: 9999;
}
}

.editor-inner {
background-color: shade($background-200, 15);
flex-grow: 1;
Expand Down
44 changes: 41 additions & 3 deletions packages/ide/src/app/tab-editor/tab-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
} from "@angular/core";
import { uploadString, ref, Storage } from "@angular/fire/storage";
import { MatSnackBar } from "@angular/material/snack-bar";
import { PortugolSyntaxError } from "@portugol-webstudio/antlr";
import { PortugolLexer, PortugolParser, PortugolSyntaxError } from "@portugol-webstudio/antlr";
import { PortugolNode, ParseError } from "@portugol-webstudio/parser";
import { PortugolExecutor, PortugolWebWorkersRunner } from "@portugol-webstudio/runner";
import { PortugolJsRuntime } from "@portugol-webstudio/runtime";
import { captureException, setExtra } from "@sentry/angular-ivy";
import { CharStreams, CommonTokenStream } from "antlr4ts";
import { saveAs } from "file-saver";
import { ShortcutInput } from "ng-keyboard-shortcuts";
import { GoogleAnalyticsService } from "ngx-google-analytics";
import { Subscription } from "rxjs";
import { Subscription, debounceTime, fromEventPattern } from "rxjs";
import { TextEncoder } from "text-encoding";

@Component({
Expand All @@ -27,6 +29,7 @@ import { TextEncoder } from "text-encoding";
styleUrls: ["./tab-editor.component.scss"],
})
export class TabEditorComponent implements OnInit, OnDestroy {
private _code$?: Subscription;
private _stdOut$?: Subscription;
private _events$?: Subscription;

Expand Down Expand Up @@ -139,8 +142,9 @@ export class TabEditorComponent implements OnInit, OnDestroy {
}

ngOnDestroy() {
this._stdOut$?.unsubscribe();
this._code$?.unsubscribe();
this._events$?.unsubscribe();
this._stdOut$?.unsubscribe();
this.executor.stop();
}

Expand Down Expand Up @@ -279,6 +283,40 @@ export class TabEditorComponent implements OnInit, OnDestroy {
onEditorInit(editor: monaco.editor.IStandaloneCodeEditor) {
this.codeEditor = editor;
this.initShortcuts(editor);

this._code$?.unsubscribe();

this._code$ = fromEventPattern(editor.onDidChangeModelContent)
.pipe(debounceTime(1000))
.subscribe(() => {
const code = this.code;

if (code) {
try {
const inputStream = CharStreams.fromString(code);
const lexer = new PortugolLexer(inputStream);
const tokenStream = new CommonTokenStream(lexer);
const parser = new PortugolParser(tokenStream);

new PortugolNode().visit(parser.arquivo());
this.setEditorErrors([]);
} catch (error) {
if (error instanceof ParseError && error.ctx.parent) {
const { _start, _stop } = error.ctx.parent as unknown as { _start: any; _stop: any };

this.setEditorErrors([
new PortugolSyntaxError(
_start._line,
_stop._line,
_start._charPositionInLine + 1,
_stop._charPositionInLine + 1 + error.ctx.text.length,
error.message,
),
]);
}
}
}
});
}

openHelp() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/src/app/tab-start/tab-start.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<hr />

<h4>📰&nbsp;&nbsp;Novidades</h4>
<p><strong>02/09/2023:</strong> Verificação básica de erros no editor.</p>
<p>
<strong>10/08/2023:</strong>
</p>
Expand All @@ -95,7 +96,6 @@ <h4>📰&nbsp;&nbsp;Novidades</h4>
</ul>

<p><strong>10/12/2022:</strong> Correção no comportamento da concatenação.</p>
<p><strong>12/11/2022:</strong> Correção na verificação de tipos de argumentos de funções.</p>
</section>

<footer>
Expand Down
2 changes: 2 additions & 0 deletions packages/parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "./helpers/ParseError.js";
export * from "./helpers/Tipo.js";
export * from "./nodes/index.js";
export * from "./PortugolNode.js";
9 changes: 8 additions & 1 deletion packages/parser/src/nodes/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ export abstract class Node {
children: Node[];

unexpectedChild(child: Node) {
const childName = child.ctx.constructor.name.replace("Context", "");
const parentName = this.ctx.constructor.name.replace("Context", "");

if (childName === "ErrorNode") {
throw new ParseError(`Expressão inválida: ${child.ctx.text}`, child.ctx);
}

throw new ParseError(
`Encontrado ${child.ctx.constructor.name} como filho de ${this.ctx.constructor.name}, não esperado: ${child.ctx.text}`,
`Encontrado '${childName}' como filho de '${parentName}', não esperado: '${child.ctx.text}'`,
child.ctx,
);
}
Expand Down

0 comments on commit f7b5a83

Please sign in to comment.