Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
Vivy
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Elliu
Vivy
Validations
20cbd79c
Valider
20cbd79c
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
WIP: Work a bit on the expression parsing
parent
f40462e0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!25
Draft: New Vivy module spec
Pipeline
#2824
en échec
Il y a 3 ans
Étape : build
Modifications
1
Pipelines
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/Lib/Script/Ast/Parser/IrExpression.hh
+30
-18
30 ajouts, 18 suppressions
src/Lib/Script/Ast/Parser/IrExpression.hh
avec
30 ajouts
et
18 suppressions
src/Lib/Script/Ast/Parser/IrExpression.hh
+
30
−
18
Voir le fichier @
20cbd79c
...
@@ -5,41 +5,53 @@ auto throwUnexpectedToken = [](const Token &tok) {
...
@@ -5,41 +5,53 @@ auto throwUnexpectedToken = [](const Token &tok) {
tok
.
toString
());
tok
.
toString
());
};
};
auto
createOpElement
=
[]
<
typename
IrT
>
(
IrExpression
*&
current
,
Token
tok
)
->
IrT
*
{
return
dynamic_cast
<
IrExpression
*>
(
IrElement
::
create
<
IrT
>
(
nullptr
,
/* The parent, will be set later */
IrT
::
getOpFromToken
(
tok
),
/* The type of operation (+,-,...) */
std
::
move
(
nullptr
),
/* We leave the left empty for now */
std
::
move
(
current
)
/* We add everything to the right */
));
};
/* <|!!|> The left will be left empty (nullptr) */
/* <|!!|> The left will be left empty (nullptr) */
auto
updateExprWithInfixOperator
=
[
throwUnexpectedToken
](
IrExpression
*&
current
,
auto
updateExprWithInfixOperator
=
[
throwUnexpectedToken
,
createOpElement
](
Token
tok
)
->
void
{
IrExpression
*&
current
,
Token
tok
)
->
void
{
/* operation -> new current, add old into right */
/* operation -> new current, add old into right */
if
(
current
->
isInfixOperator
())
if
(
current
->
isInfixOperator
())
throwUnexpectedToken
(
tok
);
throwUnexpectedToken
(
tok
);
current
=
current
=
(
tok
.
isSimple
(
TOKEN_LIST_ARITHMETIC_OP
))
(
tok
.
isSimple
(
TOKEN_LIST_ARITHMETIC_OP
))
?
createOpElement
<
IrEArithmeticOp
>
(
current
,
tok
)
?
dynamic_cast
<
IrExpression
*>
(
:
(
tok
.
isSimple
(
TOKEN_LIST_LOGIC_OP
))
?
createOpElement
<
IrELogicOp
>
(
current
,
tok
)
IrElement
::
create
<
IrEArithmeticOp
>
(
nullptr
,
IrEArithmeticOp
::
getOpFromToken
(
tok
),
:
(
tok
.
isSimple
(
TOKEN_LIST_COMP_OP
))
?
createOpElement
<
IrECompOp
>
(
current
,
tok
)
std
::
move
(
current
),
std
::
move
(
nullptr
)))
:
throw
std
::
runtime_error
(
"Can't create an infix operation from token "
+
tok
.
toString
());
:
(
tok
.
isSimple
(
TOKEN_LIST_LOGIC_OP
))
?
dynamic_cast
<
IrExpression
*>
(
IrElement
::
create
<
IrELogicOp
>
(
nullptr
,
IrELogicOp
::
getOpFromToken
(
tok
),
std
::
move
(
current
),
std
::
move
(
nullptr
)))
:
(
tok
.
isSimple
(
TOKEN_LIST_COMP_OP
))
?
dynamic_cast
<
IrExpression
*>
(
IrElement
::
create
<
IrECompOp
>
(
nullptr
,
IrECompOp
::
getOpFromToken
(
tok
),
std
::
move
(
current
),
std
::
move
(
nullptr
)))
:
nullptr
;
};
};
auto
updateExprWithConstExpr
=
[](
IrExpression
*&
current
,
Token
tok
)
->
void
{
auto
updateLeft
=
[]
<
typename
IrT
>
(
IrExpression
*
current
,
IrExpression
*
newLeft
)
->
void
{
dynamic_cast
<
IrT
*>
(
current
)
->
left
=
newLeft
;
newLeft
->
setParent
(
current
);
};
auto
updateExprWithConstExpr
=
[
updateLeft
](
IrExpression
*&
current
,
Token
tok
)
->
void
{
IrExpression
*
newLeft
=
IrElement
::
create
<
IrEConstExpr
>
(
current
,
tok
);
IrExpression
*
newLeft
=
IrElement
::
create
<
IrEConstExpr
>
(
current
,
tok
);
/* (... `op` <- currentExpression) newLeft -> currentExpression */
/* (... `op` <- currentExpression) newLeft -> currentExpression */
if
(
current
!=
nullptr
)
{
if
(
current
!=
nullptr
&&
current
->
left
==
nullptr
)
{
switch
(
current
->
type
())
{
switch
(
current
->
type
())
{
case
Type
::
CompOp
:
dynamic_cas
t
<
IrECompOp
*
>
(
current
)
->
left
=
newLeft
;
return
;
case
Type
::
CompOp
:
updateLef
t
<
IrECompOp
>
(
current
,
newLeft
)
;
return
;
case
Type
::
ArithmeticOp
:
dynamic_cas
t
<
IrEArithmeticOp
*
>
(
current
)
->
left
=
newLeft
;
return
;
case
Type
::
ArithmeticOp
:
updateLef
t
<
IrEArithmeticOp
>
(
current
,
newLeft
)
;
return
;
case
Type
::
LogicOp
:
dynamic_cas
t
<
IrELogicOp
*
>
(
current
)
->
left
=
newLeft
;
return
;
case
Type
::
LogicOp
:
updateLef
t
<
IrELogicOp
>
(
current
,
newLeft
)
;
return
;
case
Type
::
ConstExpr
:
case
Type
::
ConstExpr
:
case
Type
::
Call
:
case
Type
::
Call
:
case
Type
::
VariableRef
:
throw
std
::
runtime_error
(
"Invalid expression"
);
case
Type
::
VariableRef
:
throw
std
::
runtime_error
(
"Invalid expression"
);
}
}
}
}
/* Can be the case for `1 + 2 2` which is invalid */
else
if
(
current
!=
nullptr
&&
current
->
left
!=
nullptr
)
throw
std
::
runtime_error
(
"Unexpected token in expression parsing: "
+
tok
.
toString
());
/* newLeft -> currentExpression */
/* newLeft -> currentExpression */
else
else
current
=
newLeft
;
current
=
newLeft
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter