En tant qu'utilisateur, je veux écrire des formules à la excel pour manipuler le tableau de données dans l'application
Answer only with the result, give no explanation.
Given the following JSON data
```
{
"header": ["Produit", "Prix", "TVQ", "TPS"],
"rows": [
["Reblochon", "40", "3.99", "2"],
["Oeufs", "4", "0", "0"],
["Hotel", "100", "9.98", "5"]
]
}
```
Give the result of the formula `SUM($TPS)`
7
Answer only with the result, give no explanation.
Given the following JSON data
```
{
"header": ["Produit", "Prix", "TVQ", "TPS"],
"rows": [
["Reblochon", "40", "3.99", "2345678"],
["Oeufs", "4", "0", "0"],
["Hotel", "100", "9.98", "987654321"]
]
}
```
Give the result of the formula `SUM($TPS)`
987657999
989999999|
To
From
|
Langage naturel | Langage formel |
|---|---|---|
| Langage naturel | ChatGpt | ChatGpt |
| Langage formel | Développeur | Parser |
{"name": "Georges" /* JSON with comments */}
/invite @georges
frequency: every friday
String =>
Concrete Syntax Tree*
CST aka Parse Tree
Représentation sous forme d'arbre d'une expression
1 + 2 * 3
Expression(Number(1), Operator('+'), Expression(Number(2), Operator('*'), Number(3)))
AST
Représentation des parties signifiantes de l'expression
1 + 2 * 3
add(1, multiply(2, 3))
multiply(2,3)
Expr(Number(2),Operator('*'),Number(3))
Expr(Operator('*'), Number(2),Number(3))
Expr(Number(2),Number(3), Operator('*'))
Expr(Number('two'),Operator('times'),Number('three'))
!= Sémantiquelet x: boolean = 23;
eval et langages DSLables (ex. scala ou groovy)=> problémes de sécurité
123546.5434( 1 + 2 ) * 3T * x;Utiliser les expressions régulières - aka Regex
K1A 0B1 ou H0H 0H0[A-CEGHJ-NP-TVXY][0-9][A-CEGHJ-NP-TVXY] [0-9][A-CEGHJ-NP-TVXY][0-9]
[en]I'm in english[/en] [fr]Je suis en francais[/fr]
// What we expect
[
["en", "I'm in english", "en"],
["fr", "Je suis en francais", "fr"]
]
Vérifier l'équilibrage des balises rend le language contextuel !
+ Meilleurs performances (si on fait l'effort)
- Non portable- Le moins maintenable (même si on fait l'effort)
const OpeningTag = P.regex(/\[([a-z][a-z])\]/i, 1)
.desc("Opening tag [XX]");
const ClosingTag = P.regex(/\[\/([a-z][a-z])\]/i, 1)
.desc("Closing tag [XX]");
const Text = P.regex(/.*?(?=\[)/)
.desc("Text without [");
const Language = OpeningTag.chain(opening =>
Text.chain(text =>
ClosingTag.map(closing => [opening, text, closing]);
);
);
const Languages = Language.sepBy(P.optWhitespace)
+ Bonne maintenabilité, en particulier si on connait la programmation fonctionnelle
+ "Facile" à debugger+ Pas d'étape de build intermédiaire~Mix AST et CST- Mauvaises performances- Non portable
@{%
const moo = require("moo");
const lexer = moo.compile({
openingTag:{ match:/\[[a-zA-Z][a-zA-Z]\]/,
value: s => s.slice(1,-1).toLowerCase()},
closingTag:{ match:/\[\/[a-zA-Z][a-zA-Z]\]/,
value: s => s.slice(2,-1).toLowerCase()},
ws: {match: /\s+/, lineBreaks: true},
text: {match:/.*?(?=\[)/},});
%}
@lexer lexer
languages -> openAndCloseTag (%ws:? openAndCloseTag):* {%
([head, tail]) =>
[head, ...tail.map(([,t]) => t)] %}
openAndCloseTag-> %openingTag %text %closingTag {%
(d) => [d[0].value, d[1].value, d[2].value] %}
grammar langAntlr;
languages: openAndCloseTag (openAndCloseTag)* ;
openAndCloseTag: openingTag text closingTag ;
openingTag: OPENING_TAG ;
closingTag: CLOSING_TAG ;
text: TEXT ;
OPENING_TAG: '[' [a-zA-Z] [a-zA-Z] ']' ;
CLOSING_TAG: '[/' [a-zA-Z] [a-zA-Z] ']' ;
TEXT: CHAR+ ;
fragment CHAR: ~'[' ;
WHITESPACE : [ \t\n\r]+ -> skip ;
class Visitor extends LangAntlrVisitor {
visitLanguages(ctx) {
return super.visitLanguages(ctx);
}
visitOpenAndCloseTag(ctx) {
return super.visitOpenAndCloseTag(ctx);
}
visitClosingTag(ctx) {
return ctx.getText().slice(2, -1);
}
visitOpeningTag(ctx) {
return ctx.getText().slice(1, -1);
}
visitText(ctx) {
return ctx.getText();
}
}
+ Performance+ Portabilité- Maintenabilité- Étape de buildEBNF, ABNF (RFC 5234), etc.
begin-array = ws %x5B ws ; [ left square bracket
end-array = ws %x5D ws ; ] right square bracket
value-separator = ws %x2C ws ; , comma
quotation-mark = %x22 ; "
ws = *(%x20) ; space
null = %x6e.75.6c.6c ; null
value = null / array / string
string = quotation-mark *char quotation-mark
array = begin-array [
value *( value-separator value )
] end-array
Act as a TypeScript expert.
Answer only with code, don't give any explanation.
Create a parser based on the Parsimmon Library
that can parse the language made of the following token:
* opening tag starting with `[` ,
followed by 2 lowercase letters,
ending with `]`
* closing tag starting with `[/`,
followed by 2 lowercase letters,
ending with `]`
* an arbitrary text in between those 2 tags
eg.
`[en]a text[/en] [fr]un texte[/fr]` should return
`[ ['en', 'a text', 'en'], ['fr', 'un texte', 'fr']]`
import * as P from 'parsimmon';
const openingTag = P.string('[')
.then(P.regex(/[a-z]{2}/))
.skip(P.string(']'));
const closingTag = P.string('[/')
.then(P.regex(/[a-z]{2}/))
.skip(P.string(']'));
const text = P.takeWhile(c => c !== '[');
const tagParser = openingTag.chain(opening => {
return text.chain(content => {
return closingTag.map(closing => {
return [opening, content, closing];
});
});
});