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
98 changes: 51 additions & 47 deletions src/AST-Core-Tests/RBCodeSnippet.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ RBCodeSnippet class >> badExpressions [
notices: #( #( 1 2 4 ''')'' expected' ) )).
(self new
source: '[ ';
notices: #( #( 1 1 3 ''']'' expected' ) )).
notices: #( #( 1 2 3 ''']'' expected' ) )).
(self new
source: '#[ ';
notices: #( #( 1 2 4 ''']'' expected' ) )).
Expand Down Expand Up @@ -511,18 +511,18 @@ RBCodeSnippet class >> badExpressions [
"Unclosed blocks"
(self new
source: '[ : | ';
notices: #( #( 1 1 7 ''']'' expected' ) )).
notices: #( #( 1 6 7 ''']'' expected' ) )).
(self new
source: '[:';
formattedCode: '[ : | ';
notices: #( #( 1 1 3 ''']'' expected' ) )).
notices: #( #( 1 2 3 ''']'' expected' ) )).
(self new
source: '[ :a :b | ';
notices: #( #( 1 1 11 ''']'' expected' ) )).
notices: #( #( 1 10 11 ''']'' expected' ) )).
(self new
source: '[ :a :b';
formattedCode: '[ :a :b | ';
notices: #( #( 1 1 8 ''']'' expected' ) )).
notices: #( #( 1 7 8 ''']'' expected' ) )).
(self new
source: '[ :a a';
formattedCode: '[ :a | a';
Expand All @@ -535,7 +535,7 @@ RBCodeSnippet class >> badExpressions [
#( 1 6 7 ''']'' expected' ) )).
(self new
source: '[ :a | ';
notices: #( #( 1 1 8 ''']'' expected' ) )).
notices: #( #( 1 7 8 ''']'' expected' ) )).
(self new
source: '[ :a | a';
notices: #( #( 1 8 9 ''']'' expected' ) )).
Expand All @@ -548,10 +548,10 @@ RBCodeSnippet class >> badExpressions [
source: '[ | ';
formattedCode: '[ | | ';
notices: #( #( 3 3 5 '''|'' or variable expected' )
#( 1 3 5 ''']'' expected' ) )).
#( 1 4 5 ''']'' expected' ) )).
(self new
source: '[ | 1';
formattedCode: '[ | | 1';
formattedCode: '[ | | . 1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a dot here because you consider that the end of a unclosed block is after its temporaries declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad temps are stored into a synthetic first statement of the statement sequence to prevent ast visitors to mistake them for legit temp declarations. It's a ok design I think.

The formatter was not developed to format fauly ast (sometimes even non faulty ast :p ) so it just prints both bar (because temp declarations have two bars) and a dot (because statement, even synthetic , have a dot).

I have a wip branch that tries to fix theses formatting things.
But it's more cosmetic than useful, because formatting broken ast make little sense. The idea to check it in snippets is more to verify that parts are not lost, not the punctuation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why there wasn't a dot before the PR. Because the contents of faulty blocks were the content of the statement sequence, not the statement sequence itself. Therefore, losing possible legitimate temps, and losing the information that the contents are statements. So the content were separated with simple space instead of dots.

notices: #( #( 3 3 5 '''|'' or variable expected' )
#( 1 5 6 ''']'' expected' ) )).
(self new
Expand Down Expand Up @@ -1521,7 +1521,7 @@ RBCodeSnippet class >> badVariableAndScopes [
list := {
(self new
source: 'a := a. { [ :a }. a := a';
formattedCode: 'a := a. { [ :a | } a := a';
formattedCode: 'a := a. { [ :a | }. a := a';
raise: UndeclaredVariableWrite;
notices:
#( #( 6 6 6 'Undeclared variable' )
Expand All @@ -1540,15 +1540,14 @@ RBCodeSnippet class >> badVariableAndScopes [
#( 9 25 26 ''']'' expected' ) )).
(self new
source: 'a := a. [ :a [ :a ]. a := a';
formattedCode: 'a := a. [ :a | [ :a | ] a := a';
formattedCode: 'a := a. [ :a | [ :a | ]. a := a';
raise: UndeclaredVariableWrite;
notices:
#( #( 6 6 6 'Undeclared variable' )
#( 1 1 1 'Undeclared variable' )
#( 9 27 28 ''']'' expected' ) )).
(self new
source: 'a := a. { [ :a | }. a := a';
formattedCode: 'a := a. { [ :a | } a := a';
raise: UndeclaredVariableWrite;
notices:
#( #( 6 6 6 'Undeclared variable' )
Expand All @@ -1558,7 +1557,6 @@ RBCodeSnippet class >> badVariableAndScopes [
#( 9 26 27 '''}'' expected' ) )).
(self new
source: 'a := a. { [ :a | a := a }. a := a';
formattedCode: 'a := a. { [ :a | a := a } a := a';
raise: UndeclaredVariableWrite;
notices:
#( #( 6 6 6 'Undeclared variable' )
Expand Down Expand Up @@ -1597,50 +1595,56 @@ RBCodeSnippet class >> badVariableAndScopes [

"Chains of shadowing"
(self new
source: '[:a :a :b | | a a b | a + a + b ]';
formattedCode: '[ :a :a :b | | a a b | a + a + b ]';
source: '[ :a :a :b | | a a b | a + a + b ]';
isFaulty: false;
value: 4;
notices:
#( #( 6 6 6 'Name already defined' )
#( 15 15 15 'Name already defined' )
#( 15 15 15 'Unused variable' )
#( 17 17 17 'Name already defined' )
#( 19 19 19 'Name already defined' )
#( 23 23 23 'Unitialized variable' )
#( 27 27 27 'Unitialized variable' )
#( 31 31 31 'Unitialized variable' ) )).
#( #( 7 7 7 'Name already defined' )
#( 16 16 16 'Name already defined' )
#( 16 16 16 'Unused variable' )
#( 18 18 18 'Name already defined' )
#( 20 20 20 'Name already defined' )
#( 24 24 24 'Unitialized variable' )
#( 28 28 28 'Unitialized variable' )
#( 32 32 32 'Unitialized variable' ) )).
(self new
source:
'foo: a x: a: y: b [ :a :a :b | | a a b | a + a + b ]';
'foo: a x: a y: b [ :a :a :b | | a a b | a + a + b ]';
isMethod: true;
value: nil;
notices: #( #( 11 10 11 'Variable name expected' )
#( 14 13 14 'Variable name expected' )
#( 14 13 14 'Name already defined' )
#( 22 22 22 'Name already defined' )
#( 25 25 25 'Name already defined' )
#( 28 28 28 'Name already defined' )
#( 34 34 34 'Name already defined' )
#( 34 34 34 'Unused variable' )
#( 36 36 36 'Name already defined' )
#( 38 38 38 'Name already defined' )
#( 42 42 42 'Unitialized variable' )
#( 46 46 46 'Unitialized variable' )
#( 50 50 50 'Unitialized variable' ) )).
(self new
source: '[:a :a :b | | a a b | a + a + b';
formattedCode: '[ :a :a :b | a + a + b';
notices: #( #( 1 31 32 ''']'' expected' ) )). "FIXME where temps?"
isFaulty: false;
notices: #( #( 11 11 11 'Name already defined' )
#( 21 21 21 'Name already defined' )
#( 24 24 24 'Name already defined' )
#( 27 27 27 'Name already defined' )
#( 33 33 33 'Name already defined' )
#( 33 33 33 'Unused variable' )
#( 35 35 35 'Name already defined' )
#( 37 37 37 'Name already defined' )
#( 41 41 41 'Unitialized variable' )
#( 45 45 45 'Unitialized variable' )
#( 49 49 49 'Unitialized variable' ) )).
(self new
source: '[ :a :a :b | | a a b | a + a + b';
notices:
#( #( 16 16 16 'Unused variable' )
#( 18 18 18 'Name already defined' )
#( 24 24 24 'Unitialized variable' )
#( 28 28 28 'Unitialized variable' )
#( 32 32 32 'Unitialized variable' )
#( 1 32 33 ''']'' expected' ) )).
(self new
source:
'foo: a x: a: y: b [ :a :a :b | | a a b | a + a + b';
formattedCode: 'foo: a x: a: y: b [ :a :a :b | a + a + b';
'foo: a x: a y: b [ :a :a :b | | a a b | a + a + b';
isMethod: true;
notices: #( #( 11 10 11 'Variable name expected' )
#( 14 13 14 'Variable name expected' )
#( 14 13 14 'Name already defined' )
#( 19 50 51 ''']'' expected' ) )) "FIXME where temps?" }.
notices: #( #( 11 11 11 'Name already defined' )
#( 33 33 33 'Name already defined' )
#( 33 33 33 'Unused variable' )
#( 35 35 35 'Name already defined' )
#( 37 37 37 'Name already defined' )
#( 41 41 41 'Unitialized variable' )
#( 45 45 45 'Unitialized variable' )
#( 49 49 49 'Unitialized variable' )
#( 18 49 50 ''']'' expected' ) )) }.
"Setup default values"
self new
group: #badVariableAndScopes;
Expand Down
3 changes: 2 additions & 1 deletion src/AST-Core/RBParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ RBParser >> parseBlock [

(currentToken isSpecial: $])
ifFalse: [
^ (self parseEnglobingError: node body statements with: startToken errorMessage: ''']'' expected')
^ (self parseEnglobingError: { node body } with: startToken errorMessage: ''']'' expected')
arguments: node arguments;
stop: currentToken start - 1;
yourself
].
node right: currentToken start.
Expand Down