1.0.0 • Published 2 months ago
@juanrguezsu7/scope-intro v1.0.0
Lab: Functions
Author
- Juan
- Rodríguez Suárez
- alu0101477596@ull.edu.es
Opciones en línea de comandos (-o, -V, -h, etc.)
program
.name('calc2js')
.description('Transpile a mathematical expression to Javascript including min and max operators and functions')
.version(version, '-v, --version', 'Output the version number')
.helpOption('-h, --help', 'Display help')
.argument('[expression]', 'Expression to translate (default null)', null)
.option('-a, --ast <file>', 'File to output the AST in JSON format')
.option('-f, --file <filename>', 'Input file containing an expression to transpile')
.option('-j, --js <filename>', 'File to output the resulting Javascript')
.action((expression, options) => {
if (options.file === undefined && expression === null) {
console.error('No input expression or file provided');
program.help();
}
transpile(expression, options.file, options.js, options.ast);
});
Publicar la documentación en GH-Pages
name: Deploy static content to Pages
on:
push:
branches: ["main"]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Traduce correctamente las expresiones fuente a JS (funciones, encadenamiento de llamadas, lógica, etc.)
| fun '(' idOrNull ')' '{' e '}' { $$ = buildFunctionExpression($3, $6); }
| ID calls { $$ = buildIdCalls(buildIdentifier($($1)), $2); }
| '(' e ')' calls { $$ = buildIdCalls($2, $4); }
| e OR e { $$ = buildLogicalExpression($1, '||', $3);}
| e AND e { $$ = buildLogicalExpression($1, '&&', $3);}
| e EQUALS e { $$ = buildMemberExpression($1, 'equals', [$3]); }
let code = recast.print(ast.ast).code;
Ha añadido tests suficientes
Se han documentado el código con JSDoc o similar y publicado en GH-Pages
- Link to GitHub Pages
Se ha añadido el enlace a las GH pages en el "About" del repo
Se declaran las variables inicializadas en el preámbulo de las funciones o del programa
if (scope.length > 0) {
ast.body.unshift(scope.buildDeclaration());
}
Da mensajes de error para variables no declaradas
const NOT_DECLARED_MESSAGE = scope.notDeclaredMessage();
if (NOT_DECLARED_MESSAGE) {
console.error('*** WARNING: ' + NOT_DECLARED_MESSAGE + ' in global scope ***\n');
}
Los mensajes de error ayudan a la detección de errores
throw new Error(`Complex numbers do not support the operation ${op} for ${other}\n${e}`);
...
throw new Error(`Function does not support the operation ${op} for function ${other}`);
Las operaciones aritméticas entre funciones son soportadas (f+g)(x)
Function.prototype[op] = function(other) {
switch (typeof other) {
case 'boolean':
return (...args) => this(...args)[op](Complex(Number(other)));
case 'object':
if (other instanceof Complex) {
return (...args) => this(...args)[op](other);
} else {
throw new Error(`Function does not support the operation ${op} for ${other}`);
}
case 'function':
try {
return (...args) => this(...args)[op](other(...args));
} catch (e) {
throw new Error(`Function does not support the operation ${op} for function ${other}`);
}
case 'undefined':
return (...args) => this(...args)[op]();
default:
throw new Error(`Unsupported ${op} for type ${typeof other}`);
}
}
Es posible operar una función con un número (f+2)(x)
case 'object':
if (other instanceof Complex) {
return (...args) => this(...args)[op](other);
} else {
throw new Error(`Function does not support the operation ${op} for ${other}`);
}
Los valores booleanos son soportados y se promueven a números y a funciones correctamente
Boolean.prototype[op] = function(other) {
return Complex(Number(this))[op](other);
}
En la gramática se ha añadido la regla:
| true { $$ = buildLiteral(true); }
| false { $$ = buildLiteral(false); }
Los operadores de comparación son soportados
Complex.prototype.lessThan = function(other) {
return this.re < other.re || (this.re === other.re && this.im < other.im);
}
Herramientas de IA utilizadas
- GitHub Copilot Para la creación de los tests y documentación.
Compromiso ético
La IA no ha sido utilizada para la creación del código fuente, únicamente para la creación de los tests y la documentación, no obstruyendo el crecimiento personal y profesional propio.
(Opcional) El paquete está publicado en GitHub Registry
(Opcional) Se comprueba que el módulo npm se instala desde el GitHub Registry y funciona
(Opcional) Probar que el ejecutable queda correctamente instalado, puede ser ejecutado con el nombre publicado y produce salidas correctas
1.0.0
2 months ago