Author: mathk
Date: Wed Mar 26 11:52:47 2014
New Revision: 10648

URL: http://svn.gna.org/viewcvs/etoile?rev=10648&view=rev
Log:
Spliting ParserKit.st

Added:
    
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKMatchRangeNotice.st
    trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseAction.st
    
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParsePredicate.st
    
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseRestriction.st
    
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKRestrictedMatch.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=10648&r1=10647&r2=10648&view=diff
==============================================================================
--- trunk/Etoile/Languages/ParserKit/GNUmakefile        (original)
+++ trunk/Etoile/Languages/ParserKit/GNUmakefile        Wed Mar 26 11:52:47 2014
@@ -25,10 +25,15 @@
 ${FRAMEWORK_NAME}_SMALLTALK_BUNDLES += ParserKit.bundle
 ST_FILES = ParserKit.st\
        Utils.st\
+       PKParseAction.st\
+       PKParseRestriction.st\
+       PKRestrictedMatch.st\
+       PKParsePredicate.st\
        PKDelayActionArray.st\
        PKDelayInvocation.st\
        PKInputStream.st\
        PKEnvironmentStack.st\
+       PKMatchRangeNotice.st\
        Expressions/PKActionExpression.st\
        Expressions/PKParseExpression.st\
        Expressions/PKDotExpression.st\

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=10648&r1=10647&r2=10648&view=diff
==============================================================================
Binary files - no diff available.

Added: 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKMatchRangeNotice.st
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKMatchRangeNotice.st?rev=10648&view=auto
==============================================================================
--- 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKMatchRangeNotice.st
   (added)
+++ 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKMatchRangeNotice.st
   Wed Mar 26 11:52:47 2014
@@ -0,0 +1,55 @@
+NSObject subclass: PKMatchRangeNotice [
+       | match rule range |
+
+       initWithMatch: aMatch rule: aRule at: aRange [
+               super init.
+               match := aMatch.
+               rule := aRule.
+               range := aRange.
+       ]
+
+       canReduce [ ^true ]
+
+       isExplicitAction [
+               ^(match respondsToSelector: #isExplicitAction ) ifTrue: [
+                       (self == match) ifTrue: [ false ]
+                                      ifFalse: [ match isExplicitAction ].
+               ] ifFalse: [
+                       | action |
+                       action := match matchAction.
+                       (nil == action) ifTrue: [ false ]
+                       ifFalse: [
+                               (action isKindOfClass: PKMatchRangeNotice 
class) ifTrue: [ false ]
+                               ifFalse: [ action isExplicitAction ]
+                       ]
+               ]
+       ]
+
+       originalMatch [ ^match ]
+
+       range [ ^range ]
+
+       setOriginalMatch: aMatch [
+               match := aMatch
+       ]
+
+       reduceOn: target [
+               | selector |
+               selector := ('matched', rule, 'At:') selValue.
+               ETTranscript debug: 'Reduce called: '; debug: selector; debugCr.
+               (target respondsToSelector: selector) ifTrue: [
+                       target performSelector: selector withObject: range.
+               ] ifFalse: [
+                       target ifResponds matched: rule at: range.
+               ].
+               ^match canReduce ifTrue: [ 
+                       match reduceOn: target
+               ] ifFalse: [
+                       match match
+               ]
+       ]
+
+       description [ ^'Notice about match for ''', rule, ''' at ', range 
description ] 
+]
+
+

Added: 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseAction.st
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseAction.st?rev=10648&view=auto
==============================================================================
--- 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseAction.st    
    (added)
+++ 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseAction.st    
    Wed Mar 26 11:52:47 2014
@@ -0,0 +1,49 @@
+" 
+  Generates a delayed invocation with the arguments bound to the corresponding
+  expressions from the current parsing environment. We might want to define a
+  subclass that doesn't use invocations but instead uses the JIT to compile
+  blocks that can be executed in the environment.  
+"
+NSObject subclass: PKParseAction [
+       | selector argumentNames |
+       
+       initWithSelector: sel argumentNames: args [
+               selector := sel.
+               argumentNames := args.
+       ]
+
+       invocationInEnvironment: env originalMatch: match [
+               | argsBuild |
+               argsBuild := NSMutableArray new.
+               argumentNames do: [:each |
+                       | value |
+                       ETTranscript debug: 'Parsing with de following env.'; 
debug: env; debugCr.
+                       value := env objectForKey: each.
+                       value == nil ifTrue: [NSException raise: 'ParserKit' 
format: 'Unknown binding: ', each].
+                       argsBuild addObject: value.
+               ].
+               ^PKDelayInvocation invocationWithSelector: selector arguments: 
argsBuild originalMatch: match
+       ]
+       
+       messageString [
+               | messageString |
+               (selector description hasSuffix: ':') ifTrue: [
+                       | selectorParts |
+                       selectorParts := selector description 
componentsSeparatedByString: ':'.
+                       selectorParts := selectorParts 
zippedCollectionWithCollection: argumentNames andBlock: [ 
+                               :first :second |
+                               first, ': ', second
+                       ].
+                       messageString := selectorParts 
componentsJoinedByString: ' '.
+               ] ifFalse: [
+                       messageString := selector description.
+               ].
+               ^(messageString hasPrefix: '#') ifTrue: [
+                       messageString substringWithRange: (NSValue 
rangeWithLocation: 1 length: (messageString length - 1))
+               ] ifFalse: [ messageString ].
+       ]
+
+       description [ ^ '[', self messageString, ']' ]
+]
+
+

Added: 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParsePredicate.st
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParsePredicate.st?rev=10648&view=auto
==============================================================================
--- 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParsePredicate.st 
    (added)
+++ 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParsePredicate.st 
    Wed Mar 26 11:52:47 2014
@@ -0,0 +1,60 @@
+"
+  Parse predicates can be evaluated right away to decide whether a given
+  expression should match.
+"
+PKParseAction subclass: PKParsePredicate [
+       | targetName |
+       initWithTargetName: trgt selector: sel argumentNames: args [
+               super initWithSelector: sel argumentNames: args.
+               targetName := trgt.
+               ^self
+       ]
+
+       succeedsInEnvironment: env withDelegate: delegate [
+               | target arguments invocation |
+               arguments := argumentNames mappedCollectionWithBlock: [ 
:argName |
+                       |value |
+                       value := env objectForKey: argName.
+                       "FIXME: This is a quick hack. If the value cannot be 
bound, we assume
+                        that it should be interpreted as a literal value."
+                       value == nil ifTrue: [value := argName].
+
+                       " We might need to reduce the value first, which might 
trigger
+                         unwanted side-effects if we need to backtrack latter.
+                         TODO: In the ParserKit manual, clearly inform the 
user about
+                         the fact that it is unsafe use bound matches with 
side-effecting
+                         actions in predicates. The only thing we can avoid is 
triggering
+                         match range notices to the delegate."
+                       value canReduce ifTrue: [
+                               (value isKindOfClass: PKMatchRangeNotice class) 
ifTrue: [
+                                       | innerValue |
+                                       innerValue := value originalMatch.
+                                       innerValue canReduce ifTrue: [
+                                               innerValue := innerValue 
reduceOn: delegate.
+                                       ] ifFalse: [
+                                               innerValue := innerValue match.
+                                       ].
+                                       value setOriginalMatch: innerValue.
+                                       value := innerValue.
+                               ] ifFalse: [
+                                 value := value reduceOn: delegate.
+                                 " We also need to update the environment with 
the reduced value. "
+                                 env replaceObject: value forKey: argName.
+                               ].
+                       ].      
+                       value.
+               ].
+               target := env objectForKey: targetName.
+               target == nil ifTrue: [target := targetName].
+               invocation := NSInvocation invocationWithTarget: target 
selector: selector arguments: arguments.
+               ETTranscript show: 'Invoking selector: '; show: selector;cr.
+               invocation invoke.
+               ^invocation returnValueAsBool
+       ]
+       
+       description [
+               ^'?(', targetName, ' ', self messageString, ')'.
+       ]
+]
+
+

Added: 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseRestriction.st
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseRestriction.st?rev=10648&view=auto
==============================================================================
--- 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseRestriction.st
   (added)
+++ 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKParseRestriction.st
   Wed Mar 26 11:52:47 2014
@@ -0,0 +1,23 @@
+"
+  Parse restrictions are a reduced case of actions that can be used to replace 
a
+  match with a bound sub-expression.
+"      
+NSObject subclass: PKParseRestriction [
+       | binding |
+
+       initWithBinding: name [
+               super init.
+               binding := name.
+               ^self
+       ]
+
+       restrictInEnvironment: env [
+               | value |
+               value := env objectForKey: binding.
+               value == nil ifTrue: [NSException raise: 'ParserKit' format: 
'Unknown binding: ', binding].
+               ^PKRestrictedMatch alloc initWithResult: value
+       ]
+
+       description [ ^binding ]
+]
+

Added: 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKRestrictedMatch.st
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKRestrictedMatch.st?rev=10648&view=auto
==============================================================================
--- 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKRestrictedMatch.st
    (added)
+++ 
trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/PKRestrictedMatch.st
    Wed Mar 26 11:52:47 2014
@@ -0,0 +1,24 @@
+"
+  Restricted matches can be used just as delayed invocations, but they only
+  contain their literal value.
+"
+NSObject subclass: PKRestrictedMatch [
+       | restricted |
+       initWithResult: result [
+               super init.
+               restricted := result.
+               ^self
+       ]
+
+       reduceOn: delegate [
+               ^(restricted canReduce) ifTrue: [restricted reduceOn: delegate]
+                                      ifFalse: [restricted].   
+       ]
+       
+       canReduce [ ^true ]
+
+       isExplicitAction [ ^true ]
+
+       description [ ^restricted description ]
+]
+

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=10648&r1=10647&r2=10648&view=diff
==============================================================================
--- trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st    
(original)
+++ trunk/Etoile/Languages/ParserKit/ParserKit.bundle/Resources/ParserKit.st    
Wed Mar 26 11:52:47 2014
@@ -28,226 +28,6 @@
 
 ============================================================================
 "
-
-"
-============================================================================
-
-  Classes to implement semantic actions
-
-============================================================================
-"
-
-
-NSObject subclass: PKMatchRangeNotice [
-       | match rule range |
-
-       initWithMatch: aMatch rule: aRule at: aRange [
-               super init.
-               match := aMatch.
-               rule := aRule.
-               range := aRange.
-       ]
-
-       canReduce [ ^true ]
-
-       isExplicitAction [
-               ^(match respondsToSelector: #isExplicitAction ) ifTrue: [
-                       (self == match) ifTrue: [ false ]
-                                      ifFalse: [ match isExplicitAction ].
-               ] ifFalse: [
-                       | action |
-                       action := match matchAction.
-                       (nil == action) ifTrue: [ false ]
-                       ifFalse: [
-                               (action isKindOfClass: PKMatchRangeNotice 
class) ifTrue: [ false ]
-                               ifFalse: [ action isExplicitAction ]
-                       ]
-               ]
-       ]
-
-       originalMatch [ ^match ]
-
-       range [ ^range ]
-
-       setOriginalMatch: aMatch [
-               match := aMatch
-       ]
-
-       reduceOn: target [
-               | selector |
-               selector := ('matched', rule, 'At:') selValue.
-               ETTranscript debug: 'Reduce called: '; debug: selector; debugCr.
-               (target respondsToSelector: selector) ifTrue: [
-                       target performSelector: selector withObject: range.
-               ] ifFalse: [
-                       target ifResponds matched: rule at: range.
-               ].
-               ^match canReduce ifTrue: [ 
-                       match reduceOn: target
-               ] ifFalse: [
-                       match match
-               ]
-       ]
-
-       description [ ^'Notice about match for ''', rule, ''' at ', range 
description ] 
-]
-
-" 
-  Generates a delayed invocation with the arguments bound to the corresponding
-  expressions from the current parsing environment. We might want to define a
-  subclass that doesn't use invocations but instead uses the JIT to compile
-  blocks that can be executed in the environment.  
-"
-NSObject subclass: PKParseAction [
-       | selector argumentNames |
-       
-       initWithSelector: sel argumentNames: args [
-               selector := sel.
-               argumentNames := args.
-       ]
-
-       invocationInEnvironment: env originalMatch: match [
-               | argsBuild |
-               argsBuild := NSMutableArray new.
-               argumentNames do: [:each |
-                       | value |
-                       ETTranscript debug: 'Parsing with de following env.'; 
debug: env; debugCr.
-                       value := env objectForKey: each.
-                       value == nil ifTrue: [NSException raise: 'ParserKit' 
format: 'Unknown binding: ', each].
-                       argsBuild addObject: value.
-               ].
-               ^PKDelayInvocation invocationWithSelector: selector arguments: 
argsBuild originalMatch: match
-       ]
-       
-       messageString [
-               | messageString |
-               (selector description hasSuffix: ':') ifTrue: [
-                       | selectorParts |
-                       selectorParts := selector description 
componentsSeparatedByString: ':'.
-                       selectorParts := selectorParts 
zippedCollectionWithCollection: argumentNames andBlock: [ 
-                               :first :second |
-                               first, ': ', second
-                       ].
-                       messageString := selectorParts 
componentsJoinedByString: ' '.
-               ] ifFalse: [
-                       messageString := selector description.
-               ].
-               ^(messageString hasPrefix: '#') ifTrue: [
-                       messageString substringWithRange: (NSValue 
rangeWithLocation: 1 length: (messageString length - 1))
-               ] ifFalse: [ messageString ].
-       ]
-
-       description [ ^ '[', self messageString, ']' ]
-]
-
-
-
-"
-  Parse predicates can be evaluated right away to decide whether a given
-  expression should match.
-"
-PKParseAction subclass: PKParsePredicate [
-       | targetName |
-       initWithTargetName: trgt selector: sel argumentNames: args [
-               super initWithSelector: sel argumentNames: args.
-               targetName := trgt.
-               ^self
-       ]
-
-       succeedsInEnvironment: env withDelegate: delegate [
-               | target arguments invocation |
-               arguments := argumentNames mappedCollectionWithBlock: [ 
:argName |
-                       |value |
-                       value := env objectForKey: argName.
-                       "FIXME: This is a quick hack. If the value cannot be 
bound, we assume
-                        that it should be interpreted as a literal value."
-                       value == nil ifTrue: [value := argName].
-
-                       " We might need to reduce the value first, which might 
trigger
-                         unwanted side-effects if we need to backtrack latter.
-                         TODO: In the ParserKit manual, clearly inform the 
user about
-                         the fact that it is unsafe use bound matches with 
side-effecting
-                         actions in predicates. The only thing we can avoid is 
triggering
-                         match range notices to the delegate."
-                       value canReduce ifTrue: [
-                               (value isKindOfClass: PKMatchRangeNotice class) 
ifTrue: [
-                                       | innerValue |
-                                       innerValue := value originalMatch.
-                                       innerValue canReduce ifTrue: [
-                                               innerValue := innerValue 
reduceOn: delegate.
-                                       ] ifFalse: [
-                                               innerValue := innerValue match.
-                                       ].
-                                       value setOriginalMatch: innerValue.
-                                       value := innerValue.
-                               ] ifFalse: [
-                                 value := value reduceOn: delegate.
-                                 " We also need to update the environment with 
the reduced value. "
-                                 env replaceObject: value forKey: argName.
-                               ].
-                       ].      
-                       value.
-               ].
-               target := env objectForKey: targetName.
-               target == nil ifTrue: [target := targetName].
-               invocation := NSInvocation invocationWithTarget: target 
selector: selector arguments: arguments.
-               ETTranscript show: 'Invoking selector: '; show: selector;cr.
-               invocation invoke.
-               ^invocation returnValueAsBool
-       ]
-       
-       description [
-               ^'?(', targetName, ' ', self messageString, ')'.
-       ]
-]
-
-
-"
-  Parse restrictions are a reduced case of actions that can be used to replace 
a
-  match with a bound sub-expression.
-"      
-NSObject subclass: PKParseRestriction [
-       | binding |
-       initWithBinding: name [
-               super init.
-               binding := name.
-               ^self
-       ]
-
-       restrictInEnvironment: env [
-               | value |
-               value := env objectForKey: binding.
-               value == nil ifTrue: [NSException raise: 'ParserKit' format: 
'Unknown binding: ', binding].
-               ^PKRestrictedMatch alloc initWithResult: value
-       ]
-
-       description [ ^binding ]
-]
-
-"
-  Restricted matches can be used just as delayed invocations, but they only
-  contain their literal value.
-"
-NSObject subclass: PKRestrictedMatch [
-       | restricted |
-       initWithResult: result [
-               super init.
-               restricted := result.
-               ^self
-       ]
-
-       reduceOn: delegate [
-               ^(restricted canReduce) ifTrue: [restricted reduceOn: delegate]
-                                      ifFalse: [restricted].   
-       ]
-       
-       canReduce [ ^true ]
-
-       isExplicitAction [ ^true ]
-
-       description [ ^restricted description ]
-]
-
 "
 ============================================================================
   


_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs

Reply via email to