Skip to content

Commit

Permalink
Implementando método seletorPorVariavel() no Av. Sintático
Browse files Browse the repository at this point in the history
  • Loading branch information
VitBrandao committed Feb 19, 2025
1 parent 27959df commit c2c5312
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 28 deletions.
81 changes: 61 additions & 20 deletions fontes/avaliador-sintatico/avaliador-sintatico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Estrutura } from "../estruturas/estrutura";
import { SeletorEspacoReservado } from "../seletores/seletor-espaco-reservado";
import { AvaliadorSintaticoInterface, ImportadorInterface, SimboloInterface } from "../interfaces";
import { ValorNumerico, ValorNumericoComQuantificador } from "../../testes/listas/valor-numerico";
import { SeletorVariavel } from "../seletores/seletor-variavel";


/**
Expand Down Expand Up @@ -1146,60 +1147,98 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface {
}

protected seletorPorVariavel(): Seletor {
// console.log(this.simbolos[this.atual]);
let nomeVariavel: string;
let simboloValorVariavel: Simbolo;
let valorVariavel: string;

while (this.simbolos[this.atual].tipo !== tiposDeSimbolos.PONTO_E_VIRGULA) {
// const valorModificador = this.avancarEDevolverAnterior();
// console.log(valorModificador);
let linhaVariavel: number;
let colunaInicialVariavel: number;
let colunaFinalVariavel: number;

this.consumir(
while (this.simbolos[this.atual].tipo !== tiposDeSimbolos.PONTO_E_VIRGULA) {
const cifraoVariavel: Simbolo = this.consumir(
tiposDeSimbolos.CIFRAO,
"Esperado cifrão antes de declaração de variável."

Check warning on line 1161 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
)

this.consumir(
colunaInicialVariavel = cifraoVariavel.colunaInicial;

Check warning on line 1164 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
linhaVariavel = cifraoVariavel.linha;

Check warning on line 1165 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const declaracaoVariavel: Simbolo = this.consumir(
tiposDeSimbolos.VARIAVEL,
"Esperada declaração de variável."

Check warning on line 1169 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
)

nomeVariavel = declaracaoVariavel.lexema;

Check warning on line 1172 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (this.simbolos[this.atual].tipo === tiposDeSimbolos.DOIS_PONTOS) {
this.consumir(
tiposDeSimbolos.DOIS_PONTOS,
"Esperado ':' após declaração de variável."
);



switch (this.simbolos[this.atual].tipo) {
case tiposDeSimbolos.IDENTIFICADOR:
this.consumir(
simboloValorVariavel = this.consumir(
tiposDeSimbolos.IDENTIFICADOR,
"Esperado nome do modificador após declaração de variável."
);

Check warning on line 1186 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

valorVariavel = simboloValorVariavel.lexema;

Check warning on line 1188 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
break;

Check warning on line 1189 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
case tiposDeSimbolos.QUALITATIVO:
this.consumir(
simboloValorVariavel = this.consumir(
tiposDeSimbolos.QUALITATIVO,
"Esperado qualitativo após declaração de variável."
);

Check warning on line 1194 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

valorVariavel = simboloValorVariavel.lexema;

Check warning on line 1196 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
break;

Check warning on line 1197 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 1197 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
case tiposDeSimbolos.NUMERO:
simboloValorVariavel = this.consumir(
tiposDeSimbolos.NUMERO,
"Esperado valor numérico após declaração de variável"
);

Check warning on line 1202 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

valorVariavel = simboloValorVariavel.lexema;

Check warning on line 1204 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const proximoSimbolo: Simbolo = this.avancarEDevolverAnterior();

Check warning on line 1206 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (proximoSimbolo.tipo === tiposDeSimbolos.QUANTIFICADOR) {
const quantificadorVariavel = this.consumir(
tiposDeSimbolos.QUANTIFICADOR,
"Esperado quantificador após valor numérico atribuído à variável."

Check warning on line 1210 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
)

valorVariavel += quantificadorVariavel.lexema;

Check warning on line 1213 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 1214 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 1214 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 1215 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
case tiposDeSimbolos.METODO:
this.resolverMetodo(this.simbolos[this.atual - 1].lexema);
break;
default:
console.log('nao deveria cair aqui')
console.log('Não deveria cair aqui!')

Check warning on line 1220 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 1220 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 1221 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 1222 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 1222 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

}

Check warning on line 1223 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

// RETORNO GENÉRICO PARA EVITAR ERROS PONTUAIS
const pseudoclasse = this.resolverPseudoclasse();
return new SeletorClasse(
'lexema',
pseudoclasse,
// console.log('nome', nomeVariavel);
// console.log('valor', valorVariavel);

const pontoVirgulaVariavel: Simbolo = this.consumir(
tiposDeSimbolos.PONTO_E_VIRGULA,
"Esperado ponto e vírgula após atribuição de valor à variável"

Check warning on line 1230 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);

colunaFinalVariavel = pontoVirgulaVariavel.colunaFinal - 1;

Check warning on line 1233 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return new SeletorVariavel(
nomeVariavel,
valorVariavel,
{
linha: 0,
colunaInicial: 0,
colunaFinal: 0
linha: linhaVariavel,
colunaInicial: colunaInicialVariavel,
colunaFinal: colunaFinalVariavel,
}
);

Check warning on line 1243 in fontes/avaliador-sintatico/avaliador-sintatico.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
Expand Down Expand Up @@ -1353,6 +1392,8 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface {
return null;
default:
const seletores = this.resolverSeletores();
// console.log('SELETORES', seletores);

const modificadoresEDeclaracoesAninhadas = this.resolverModificadoresEDeclaracoesAninhadas();

return new Declaracao(
Expand All @@ -1372,7 +1413,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface {
while (!this.estaNoFinal()) {
declaracoes.push(this.declaracao());
}

return declaracoes.filter(d => d);
}
}
15 changes: 7 additions & 8 deletions fontes/seletores/seletor-variavel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { PragmasSeletor } from "./pragmas-seletor";
import { Seletor } from "./seletor";

export class SeletorVariavel extends Seletor {
nomeClasse: string;
nomeVariavel: string;
valorVariavel: string;
pragmas?: PragmasSeletor;

constructor(nomeClasse: string, pseudoclasse?: Pseudoclasse, pragmas?: PragmasSeletor) {
super(pseudoclasse, pragmas);
this.nomeClasse = nomeClasse;
constructor(nomeVariavel: string, valorVariavel: string, pragmas?: PragmasSeletor) {

Check warning on line 10 in fontes/seletores/seletor-variavel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
super(null, pragmas);

Check warning on line 11 in fontes/seletores/seletor-variavel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.nomeVariavel = nomeVariavel;

Check warning on line 12 in fontes/seletores/seletor-variavel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.valorVariavel = valorVariavel;

Check warning on line 13 in fontes/seletores/seletor-variavel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

paraTexto() {
let resultado = `.${this.nomeClasse}`;
if (this.pseudoclasse !== undefined && this.pseudoclasse !== null) {
resultado += `:${this.pseudoclasse.pseudoclasseCss}`;
}
let resultado = `$${this.nomeVariavel}: ${this.valorVariavel}`;

Check warning on line 17 in fontes/seletores/seletor-variavel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return resultado;
}
Expand Down

0 comments on commit c2c5312

Please sign in to comment.