Skip to content

Commit

Permalink
fix case with ' at the end.
Browse files Browse the repository at this point in the history
Also guard parsed string from being a Text as literal value
  • Loading branch information
dionisiydk committed Feb 27, 2020
1 parent a1e2ba4 commit ef0a15f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
35 changes: 35 additions & 0 deletions src/AST-Core-Tests/RBParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ RBParserTest >> testParseFaultyMethod [
add: 'method: asd ^ asd. n'; "invalid expresion after return"
add: 'method: asd ^ {'; "Only Open a literal array"
add: 'selector ''';
add: 'selector ''part1''''part2'; "string with escaped ' does not end"
add: 'selector #^';
add: 'selector ¿';
add: ':nl'.
Expand Down Expand Up @@ -545,6 +546,40 @@ RBParserTest >> testParseFaultyPragma [
self assert: node pragmas first isFaulty
]
{ #category : #'tests parsing' }
RBParserTest >> testParseMethodWhichEndsWithUncompleteStringWithEscapedMarkAtTheEnd [
| node strangeMethod body statement message errorNode |
strangeMethod := '
selector
|temp|
temp := ''this is right'', ''wrong'''''.
node := self parseFaultyMethod: strangeMethod.
self assert: node isMethod.
self assert: node isFaulty.
self assertEmpty: node arguments.
body := node body.
self assert: body isSequence.
self assert: body isFaulty.
self assert: (body temporaries includes: (RBVariableNode named: 'temp')).
statement := body statements first.
self assert: statement isFaulty.
self assert: statement isAssignment.
message := statement value.
self assert: message isFaulty.
self assert: message arguments size equals: 1.
errorNode := message arguments at: 1.
self assert: errorNode isFaulty.
self
assert: errorNode value
equals: 'wrong'''.
self assert: errorNode errorMessage equals: 'Unmatched '' in string literal.' translated
]
{ #category : #'tests parsing' }
RBParserTest >> testParseMethodWithErrorTokenIsWellFormed [
| node strangeMethod body statement message errorNode |
Expand Down
18 changes: 14 additions & 4 deletions src/AST-Core/RBScanner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,14 @@ RBScanner >> scanLiteralCharacter [
{ #category : #'private-scanning' }
RBScanner >> scanLiteralString [
| string |
[stream atEnd ifTrue: [^ self scanError: 'Unmatched '' in string literal.'].
string := stream upTo: $'.
stream peekBack = $' ifFalse: [
[stream atEnd ifTrue: [
self step. "to handle eof"
^ self scanError: 'Unmatched '' in string literal.'].
string := stream upTo: $'.
stream peekBack = $' ifFalse: [
"the peek logic here is because #upTo: does not tell if given char was found"
buffer nextPutAll: string.
self step. "to handle eof"
^ self scanError: 'Unmatched '' in string literal.'].
self step = $'] whileTrue: [
Expand All @@ -463,7 +467,13 @@ RBScanner >> scanLiteralString [
buffer position = 0 ifFalse: [
buffer nextPutAll: string.
string := buffer contents].
^RBLiteralToken value: string start: tokenStart stop: self previousStepPosition
"It's possible to use a plain Text for parsing.
In that case string here could be a Text instance but literal value must be a String"
^RBLiteralToken
value: string asString
start: tokenStart
stop: self previousStepPosition
]
{ #category : #'private-scanning' }
Expand Down

0 comments on commit ef0a15f

Please sign in to comment.