help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] gst-convert: Handle ==> selector in rewrite rul


From: Holger Hans Peter Freyther
Subject: [Help-smalltalk] [PATCH] gst-convert: Handle ==> selector in rewrite rules
Date: Sat, 29 Sep 2012 16:51:44 +0200

From: Holger Hans Peter Freyther <address@hidden>

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 '(address@hidden ==> address@hidden 
)
-> (address@hidden => address@hidden)'.

2012-09-29  Holger Freyther  <address@hidden>

        * 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  <address@hidden>
 
+       * scripts/Convert.st: Collect all rewrite expressions and parse
+       them with the selected parser.
+
+2012-09-29  Holger Freyther  <address@hidden>
+
        * 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]