[PATCH] gst-convert: Handle ==> selector in rewrite rules

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] gst-convert: Handle ==> selector in rewrite rules

Holger Freyther
From: Holger Hans Peter Freyther <[hidden email]>

When converting PetitParser client code from Pharo to GNU Smalltalk
one will need to replace longer binary selectors like ==> with a shorter
version of them. Use the parser class of the input to parse the rule.
Ideally we would use the parser for the left side of the rule and the
exporter for the right side of the rule but this is not possible yet.
Collect all rules until after the parser class was selected, then add
the rules to the converter.

This patch allows to parse a rule like this '(``@object ==> ``@arg1 )
-> (``@object => ``@arg1)'.

2012-09-29  Holger Freyther  <[hidden email]>

        * scripts/Convert.st: Collect all rewrite expressions and parse
        them with the parser for the code.
---
 ChangeLog          |    5 +++++
 scripts/Convert.st |   13 +++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 694ec33..8c08ade 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2012-09-29  Holger Freyther  <[hidden email]>
 
+ * scripts/Convert.st: Collect all rewrite expressions and parse
+ them with the selected parser.
+
+2012-09-29  Holger Freyther  <[hidden email]>
+
  * tests/stcompiler.st: Add testcase for parsing 16rff.
  * tests/stcompiler.ok: Update the test result.
 
diff --git a/scripts/Convert.st b/scripts/Convert.st
index bc86aba..0361d48 100644
--- a/scripts/Convert.st
+++ b/scripts/Convert.st
@@ -263,9 +263,9 @@ STInST.STClassLoader subclass: SyntaxConverter [
         ^super evaluate: rewritten
     ]
     
-    addRule: searchString [
+    addRule: searchString parser: aParserClass [
  | tree rule |
- tree := RBParser parseRewriteExpression: searchString.
+ tree := aParserClass parseRewriteExpression: searchString.
  tree isMessage ifFalse: [ self error: 'expected ->' ].
  tree selector = #-> ifFalse: [ self error: 'expected ->' ].
  rule := RBStringReplaceRule
@@ -404,7 +404,7 @@ String extend [
 
 Eval [
     | helpString inFile outFile quiet verbose converter filter parser
- args inFormats outFormats |
+ args inFormats outFormats rules |
     args := OrderedCollection new.
     parser := STInST.STFileInParser.
     quiet := false.
@@ -424,6 +424,7 @@ Eval [
  'squeak' -> STInST.SqueakFileInParser.
  'sif' -> STInST.SIFFileInParser
     }.
+    rules := OrderedCollection new.
     
     helpString :=
 'Usage:
@@ -483,7 +484,7 @@ Options:
  outFile := arg ].
 
     opt = 'rule' ifTrue: [
- converter addRule: arg ].
+ rules add: arg].
 
     opt = 'class' ifTrue: [
  [ 'a' ~ arg ] on: Error do: [ :ex |
@@ -522,6 +523,10 @@ Options:
             helpString displayOn: stderr.
             ObjectMemory quit: 1 ].
 
+    "Post process the rules now we know the target."
+    rules do: [:rule |
+ converter addRule: rule parser: parser].
+
     [
         outFile isNil
     ifTrue: [
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk