Author: mathk
Date: Wed Mar 26 15:11:33 2014
New Revision: 10649
URL: http://svn.gna.org/viewcvs/etoile?rev=10649&view=rev
Log:
Splitting ParserKit
Added:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKAlphanumericExpression.st
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKNonTerminalExpression.st
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKParameterizedExpression.st
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKTokenExpression.st
Modified:
trunk/Etoile/Languages/ParserKit/GNUmakefile
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/LKInfo.plist
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st
Modified: trunk/Etoile/Languages/ParserKit/GNUmakefile
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/GNUmakefile?rev=10649&r1=10648&r2=10649&view=diff
==============================================================================
--- trunk/Etoile/Languages/ParserKit/GNUmakefile (original)
+++ trunk/Etoile/Languages/ParserKit/GNUmakefile Wed Mar 26 15:11:33 2014
@@ -43,11 +43,15 @@
Expressions/PKWhitespaceExpression.st\
Expressions/PKRangeExpression.st\
Expressions/PKNumericExpression.st\
+ Expressions/PKNonTerminalExpression.st\
+ Expressions/PKAlphanumericExpression.st\
Expressions/PKNAryComposeExpression.st\
Expressions/PKComposeExpression.st\
Expressions/PKEmptyExpression.st\
Expressions/PKRestrictionExpression.st\
Expressions/PKAnythingExpression.st\
+ Expressions/PKParameterizedExpression.st\
+ Expressions/PKTokenExpression.st\
Generator/PKParserAbstractGenerator.st
SMALLTALK_BUNDLE_ST_FILES=$(addprefix
./ParserKit.bundle/Resources/,$(ST_FILES))
Added:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKAlphanumericExpression.st
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKAlphanumericExpression.st?rev=10649&view=auto
==============================================================================
---
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKAlphanumericExpression.st
(added)
+++
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKAlphanumericExpression.st
Wed Mar 26 15:11:33 2014
@@ -0,0 +1,10 @@
+PKComposeExpression subclass: PKAlphanumericExpression [
+
+ init [
+ self initWithExp: ( PKAlphabeticExpression new or:
PKNumericExpression new )
+ ]
+
+ description [^'[[:alnum:]]']
+]
+
+
Added:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKNonTerminalExpression.st
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKNonTerminalExpression.st?rev=10649&view=auto
==============================================================================
---
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKNonTerminalExpression.st
(added)
+++
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKNonTerminalExpression.st
Wed Mar 26 15:11:33 2014
@@ -0,0 +1,56 @@
+PKComposeExpression subclass: PKNonTerminalExpression [
+ | name |
+ initWithName: string exp: expression [
+ super init.
+ exp := expression.
+ name := string.
+ ^self
+ ]
+
+ parseInput: list withCurrentParser: parser delegate: delegate [
+ | match |
+ list inEnvironmentDo: [
+ exp == nil ifTrue: [NSException raise: 'ParserKit'
format: 'Uncomplete grammar definition for ', name].
+ ETTranscript debug: 'Trying non terminal: ', name, '
input pos: '; debug: list positionStack; debugCr.
+ match := list matchRule: name.
+ (match == nil) ifTrue: [
+ | position |
+ position := list position.
+
+ match := exp parseInput: list
withCurrentParser: parser delegate: delegate.
+ match isSuccess ifTrue: [
+ " Add an implicit range notice "
+ (match matchAction == nil) ifTrue: [
+ match attachAction:
(PKMatchRangeNotice alloc
+ initWithMatch: match
+ rule: name
+ at: match range)
+ ] ifFalse: [
+ " If there is already an
action, we need to use that for
+ the match "
+ (match matchAction
isKindOfClass: PKMatchRangeNotice class) ifFalse: [
+ match attachAction:
(PKMatchRangeNotice alloc
+ initWithMatch:
match matchAction
+ rule: name
+ at:
match range)
+ ]
+ ].
+ ].
+ " Only memoize the matches from expressions for
which it is safely possible. "
+ "exp isMemoizable ifTrue: [list addMatch: match
at: position named: name]."
+ ] ifFalse: [ match isSuccess ifTrue: [
+ ETTranscript debug: 'Pushing back position: ';
debug: match stopPosition; debugCr.
+ list pushPosition: match stopPosition.
+ ]
+ ifFalse: [
ETTranscript debug: 'Memo Catch failure for ', name; debugCr]
+ ].
+ ETTranscript debug: 'End of non terminal: ', name, '
input pos: '; debug: list positionStack; debug: 'last position: '; debug: list
position; debug: ', match: '; debug: match matchText; debugCr.
+ ].
+ ^match
+ ]
+
+ setExpression: anExp [ exp := anExp ]
+ description [^name]
+]
+
+
Added:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKParameterizedExpression.st
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKParameterizedExpression.st?rev=10649&view=auto
==============================================================================
---
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKParameterizedExpression.st
(added)
+++
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKParameterizedExpression.st
Wed Mar 26 15:11:33 2014
@@ -0,0 +1,27 @@
+
+PKComposeExpression subclass: PKParameterizedExpression [
+ | predicate |
+ initWithExp: aExp predicate: pred [
+ super initWithExp: aExp.
+ predicate := pred.
+ ]
+ parseInput: list withCurrentParser: parser delegate: delegate [
+ | match |
+ match := exp parseInput: list withCurrentParser: parser
delegate: delegate.
+ ^match isSuccess ifTrue: [
+ (predicate succeedsInEnvironment: (list environment)
withDelegate: delegate) ifTrue: [ match ]
+ ifFalse: [
+ list popPosition.
+ PKParseFail alloc initWithInput: list
+ description: ('Expected ',
exp description, ' to satisfy parameter ', predicate description)].
+ ] ifFalse: [ match ].
+ ]
+
+ description [
+ ^exp description, ' ', predicate description
+ ]
+
+ isMemoizable [ ^false ]
+ isMemoizableForNonTerminal: name inGrammar: grammar [ ^false ]
+]
+
Added:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKTokenExpression.st
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKTokenExpression.st?rev=10649&view=auto
==============================================================================
---
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKTokenExpression.st
(added)
+++
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/Expressions/PKTokenExpression.st
Wed Mar 26 15:11:33 2014
@@ -0,0 +1,26 @@
+PKParseExpression subclass: PKTokenExpression [
+ | match |
+
+ initWithPattern: matchPattern [
+ super init.
+ match := matchPattern.
+ ^self
+ ]
+
+ parseInput: list withCurrentParser: parser delegate: delegate [
+ | return |
+ ((list head: match matchSize) isEqual: match) ifTrue: [
+ return := PKParseMatch alloc initWithInput: list
+ length: match
matchSize.
+ ] ifFalse: [
+ return := PKParseFail alloc initWithInput: list
description: 'Unexpected token, expected: ', match
+ ].
+ ^return
+ ]
+
+ description [
+ ^'''', match description, ''''
+ ]
+]
+
+
Modified:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/LKInfo.plist
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/LKInfo.plist?rev=10649&r1=10648&r2=10649&view=diff
==============================================================================
Binary files - no diff available.
Modified:
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st?rev=10649&r1=10648&r2=10649&view=diff
==============================================================================
--- trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st
(original)
+++ trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st
Wed Mar 26 15:11:33 2014
@@ -35,122 +35,6 @@
============================================================================
"
-PKComposeExpression subclass: PKParameterizedExpression [
- | predicate |
- initWithExp: aExp predicate: pred [
- super initWithExp: aExp.
- predicate := pred.
- ]
- parseInput: list withCurrentParser: parser delegate: delegate [
- | match |
- match := exp parseInput: list withCurrentParser: parser
delegate: delegate.
- ^match isSuccess ifTrue: [
- (predicate succeedsInEnvironment: (list environment)
withDelegate: delegate) ifTrue: [ match ]
- ifFalse: [
- list popPosition.
- PKParseFail alloc initWithInput: list
- description: ('Expected ',
exp description, ' to satisfy parameter ', predicate description)].
- ] ifFalse: [ match ].
- ]
-
- description [
- ^exp description, ' ', predicate description
- ]
-
- isMemoizable [ ^false ]
- isMemoizableForNonTerminal: name inGrammar: grammar [ ^false ]
-]
-
-PKComposeExpression subclass: PKNonTerminalExpression [
- | name |
- initWithName: string exp: expression [
- super init.
- exp := expression.
- name := string.
- ^self
- ]
-
- parseInput: list withCurrentParser: parser delegate: delegate [
- | match |
- list inEnvironmentDo: [
- exp == nil ifTrue: [NSException raise: 'ParserKit'
format: 'Uncomplete grammar definition for ', name].
- ETTranscript debug: 'Trying non terminal: ', name, '
input pos: '; debug: list positionStack; debugCr.
- match := list matchRule: name.
- (match == nil) ifTrue: [
- | position |
- position := list position.
-
- match := exp parseInput: list
withCurrentParser: parser delegate: delegate.
- match isSuccess ifTrue: [
- " Add an implicit range notice "
- (match matchAction == nil) ifTrue: [
- match attachAction:
(PKMatchRangeNotice alloc
- initWithMatch: match
- rule: name
- at: match range)
- ] ifFalse: [
- " If there is already an
action, we need to use that for
- the match "
- (match matchAction
isKindOfClass: PKMatchRangeNotice class) ifFalse: [
- match attachAction:
(PKMatchRangeNotice alloc
- initWithMatch:
match matchAction
- rule: name
- at:
match range)
- ]
- ].
- ].
- " Only memoize the matches from expressions for
which it is safely possible. "
- "exp isMemoizable ifTrue: [list addMatch: match
at: position named: name]."
- ] ifFalse: [ match isSuccess ifTrue: [
- ETTranscript debug: 'Pushing back position: ';
debug: match stopPosition; debugCr.
- list pushPosition: match stopPosition.
- ]
- ifFalse: [
ETTranscript debug: 'Memo Catch failure for ', name; debugCr]
- ].
- ETTranscript debug: 'End of non terminal: ', name, '
input pos: '; debug: list positionStack; debug: 'last position: '; debug: list
position; debug: ', match: '; debug: match matchText; debugCr.
- ].
- ^match
- ]
-
- setExpression: anExp [ exp := anExp ]
- description [^name]
-]
-
-PKComposeExpression subclass: PKAlphanumericExpression [
-
- init [
- self initWithExp: ( PKAlphabeticExpression new or:
PKNumericExpression new )
- ]
-
- description [^'[[:alnum:]]']
-]
-
-
-PKParseExpression subclass: PKTokenExpression [
- | match |
-
- initWithPattern: matchPattern [
- super init.
- match := matchPattern.
- ^self
- ]
-
- parseInput: list withCurrentParser: parser delegate: delegate [
- | return |
- ((list head: match matchSize) isEqual: match) ifTrue: [
- return := PKParseMatch alloc initWithInput: list
- length: match
matchSize.
- ] ifFalse: [
- return := PKParseFail alloc initWithInput: list
description: 'Unexpected token, expected: ', match
- ].
- ^return
- ]
-
- description [
- ^'''', match description, ''''
- ]
-]
-
PKParseExpression subclass: PKSequenceExpression [
| e1 e2 |
_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs