Added children nodes, better printOn: and some more documentation.
--- a/ParseErrorNode.st Sat Aug 10 13:24:32 2013 +0200
+++ b/ParseErrorNode.st Thu Aug 15 16:20:56 2013 +0200
@@ -12,7 +12,7 @@
"{ Package: 'stx:libcomp' }"
ParseNode subclass:#ParseErrorNode
- instanceVariableNames:'errorString errorToken'
+ instanceVariableNames:'errorString errorToken children'
classVariableNames:''
poolDictionaries:''
category:'System-Compiler-Support'
@@ -32,6 +32,44 @@
other person. No title to or ownership of the software is
hereby transferred.
"
+!
+
+documentation
+"
+ ParseErrorNode represent an errorneous portion of the source code.
+ Error nodes are created by error-tolerant parser. So far the only
+ user is SmallSenseParser (https://bitbucket.org/janvrany/jv-smallsense).
+
+ Error nodes may have children which may not be error nodes. Such
+ children represent a part of the code that actuallu could be parsed.
+ Example:
+
+ printValue: value
+ Transcript show: (value printStringRadix: 12
+ Transcript cr
+
+ The tolerant parser may create tree like:
+ statement (StatementNode)
+ #show: (MessageNode)
+ Transcript (ContantNode)
+ <<error>> (ParseErrorNode)
+ #printStringRadix: (MessageNode)
+ value (VariableNode)
+ 12 (ContantNode)
+ statement (StatementNode)
+ #cr (MessageNode)
+ Transcript (ContantNode)
+
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+
+ [class variables:]
+
+ [see also:]
+
+"
! !
!ParseErrorNode class methodsFor:'instance creation'!
@@ -42,6 +80,17 @@
!ParseErrorNode methodsFor:'accessing'!
+children
+ ^ children
+!
+
+children:aCollection
+ children := aCollection.
+ children do:[:each | each parent: self ].
+
+ "Modified: / 15-08-2013 / 11:43:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
errorString
^ errorString
!
@@ -81,19 +130,32 @@
!ParseErrorNode methodsFor:'printing & storing'!
+printAllOn:aStream indent:indent
+ children do: [:each | each printAllOn:aStream indent:indent ].
+ self printOn:aStream indent:indent
+
+ "Created: / 15-08-2013 / 12:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
printOn:aStream indent:indent
"append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back."
aStream next: indent put: Character tab.
+ aStream nextPutAll:'"<< parse error here'.
+ errorString notNil ifTrue:[
+ aStream nextPutAll:': '.
+ aStream nextPutAll: errorString
+ ].
errorToken notNil ifTrue:[
- aStream nextPutAll: errorToken
- ] ifFalse: [
- aStream nextPutAll:'"<< parse error here >>"'
- ]
+ aStream nextPutAll:' (error token: '.
+ aStream nextPutAll: errorToken.
+ aStream nextPutAll: ')'.
+ ].
+ aStream nextPutAll:'>>"'
"Created: / 20-04-2005 / 14:21:46 / cg"
- "Modified: / 08-03-2012 / 20:52:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-08-2013 / 12:32:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!ParseErrorNode methodsFor:'queries'!
@@ -116,9 +178,10 @@
!ParseErrorNode class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/ParseErrorNode.st,v 1.6 2012-03-09 07:48:24 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/ParseErrorNode.st,v 1.7 2013-08-15 14:20:56 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libcomp/ParseErrorNode.st,v 1.6 2012-03-09 07:48:24 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/ParseErrorNode.st,v 1.7 2013-08-15 14:20:56 vrany Exp $'
! !
+