Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions examples/convDate.lm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@ main(){
a, b, c : int
}

a := 1
b := 10
c := 1900

convDate(11,11,1900)
convDate(a,b,c)
convDate(11,b,1900)
convDate(a,11,c)
convDate(11-11-1900)
}
3 changes: 1 addition & 2 deletions inputs/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ main(){
#+ Ejemplo de error por entero mayor a 64 bits +#
#+ x:= 18446744073709551616 +#

convDate(1,2,1900)
convDate(a1,2,1900)
convDate(01-02-1900)
}
1,006 changes: 364 additions & 642 deletions src/grammar.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/grammar.rustemo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FunctionWrite: TokenWrite TokenParOpen SimpleExpression TokenParClose {FunctionW

FunctionIsZero: TokenIsZero TokenParOpen ArithmeticExpression TokenParClose {FunctionIsZeroCall};

FunctionConvDate: TokenConvDate TokenParOpen IntegerValue TokenComma IntegerValue TokenComma IntegerValue TokenParClose {FunctionConvDateVariableCall};
FunctionConvDate: TokenConvDate TokenParOpen TokenDate TokenParClose {FunctionConvDateVariableCall};

VarDeclarations: VarDeclaration {VarDeclarationsSingle}
| VarDeclaration VarDeclarations {VarDeclarationsRecursive};
Expand Down Expand Up @@ -129,3 +129,4 @@ TokenRead:;
TokenWrite:;
TokenIsZero:;
TokenConvDate:;
TokenDate:;
27 changes: 10 additions & 17 deletions src/grammar_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ pub fn token_conv_date(_ctx: &Ctx, token: Token) -> TokenConvDate {
write_to_lexer_file(&format!("CONV_DATE: {}", token.value));
token.value.into()
}
pub type TokenDate = String;
pub fn token_date(_ctx: &Ctx, token: Token) -> TokenDate {
write_to_lexer_file(&format!("DATE: {}", token.value));
token.value.into()
}
#[derive(Debug, Clone)]
pub struct Program {
pub token_id: TokenId,
Expand Down Expand Up @@ -408,35 +413,23 @@ pub fn function_is_zero_function_is_zero_call(
pub struct FunctionConvDate {
pub token_conv_date: TokenConvDate,
pub token_par_open: TokenParOpen,
pub integer_token_3: IntegerValue,
pub token_comma_4: TokenComma,
pub integer_token_5: IntegerValue,
pub token_comma_6: TokenComma,
pub integer_token_7: IntegerValue,
pub token_date: TokenDate,
pub token_par_close: TokenParClose,
}
pub fn function_conv_date_function_conv_date_variable_call(
_ctx: &Ctx,
token_conv_date: TokenConvDate,
token_par_open: TokenParOpen,
integer_token_3: IntegerValue,
token_comma_4: TokenComma,
integer_token_5: IntegerValue,
token_comma_6: TokenComma,
integer_token_7: IntegerValue,
token_date: TokenDate,
token_par_close: TokenParClose,
) -> FunctionConvDate {
write_to_parser_file(&format!(
"<FunctionConvDate> -> {token_conv_date} {token_par_open} <IntegerValue> {token_comma_4} <IntegerValue> {token_comma_6} <IntegerValue> {token_par_close}"
"<FunctionConvDate> -> {token_conv_date} {token_par_open} {token_date} {token_par_close}"
));
FunctionConvDate {
token_conv_date,
token_par_open,
integer_token_3,
token_comma_4,
integer_token_5,
token_comma_6,
integer_token_7,
token_date,
token_par_close,
}
}
Expand Down Expand Up @@ -768,7 +761,7 @@ pub fn boolean_expression_boolean_expression_simple_expression_recursive(
boolean_expression: BooleanExpression,
) -> BooleanExpression {
write_to_parser_file(&format!(
"<BooleanExpression> -> <SimpleExpression> <BooleanExpressionChain> {conjunction:?} <BooleanExpression>"
"<BooleanExpression> -> <SimpleExpression> <BooleanExpressionChain> <Conjunction> <BooleanExpression>"
));
BooleanExpression::BooleanExpressionSimpleExpressionRecursive(
BooleanExpressionSimpleExpressionRecursive {
Expand Down
1 change: 1 addition & 0 deletions src/grammar_lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl Display for TokenKind {
Self::TokenWrite => "\"write\"",
Self::TokenIsZero => "\"isZero\"",
Self::TokenConvDate => "\"convDate\"",
Self::TokenDate => "\"date\"",
};
write!(f, "{text}")
}
Expand Down
1 change: 1 addition & 0 deletions src/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::grammar::TokenKind;
"write" return Ok(TokenKind::TokenWrite);
"isZero" return Ok(TokenKind::TokenIsZero);
"convDate" return Ok(TokenKind::TokenConvDate);
([0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]) return Ok(TokenKind::TokenDate);
([0-9]+) return Ok(TokenKind::TokenIntLiteral);
(([0-9]+("."[0-9]*)?|"."[0-9]+)([eE][-+]?[0-9]+)?) return Ok(TokenKind::TokenFloatLiteral);
[a-zA-Z]([a-zA-Z]|[0-9])* return Ok(TokenKind::TokenId);
Expand Down
272 changes: 139 additions & 133 deletions src/lex.rs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ fn integration_test(path: &Path) -> datatest_stable::Result<()> {
}

#[cfg(test)]
datatest_stable::harness!( { test = integration_test, root = "./examples", pattern = r".*\.lm" },);
datatest_stable::harness!(
{ test = integration_test, root = "./examples", pattern = r".*\.lm" },
{ test = integration_test, root = "./inputs", pattern = r"test.txt" }
);