- Juan
- Rodríguez Suárez
- alu0101477596@ull.edu.es
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);
});
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;
- Link to GitHub Pages
if (scope.length > 0) {
ast.body.unshift(scope.buildDeclaration());
}
const NOT_DECLARED_MESSAGE = scope.notDeclaredMessage();
if (NOT_DECLARED_MESSAGE) {
console.error('*** WARNING: ' + NOT_DECLARED_MESSAGE + ' in global scope ***\n');
}
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}`);
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}`);
}
}
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}`);
}
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); }
Complex.prototype.lessThan = function(other) {
return this.re < other.re || (this.re === other.re && this.im < other.im);
}
- GitHub Copilot Para la creación de los tests y documentación.
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.