From b9ab6e0da0c2ed62f400b0b8f63322c5f9c0fc4c Mon Sep 17 00:00:00 2001
From: Michał Lenart <michall@ipipan.waw.pl>
Date: Sun, 7 Dec 2014 22:07:35 +0000
Subject: [PATCH] dodanie możliwości doklejania ">" do wyrażeń nawiasowych

---
 fsabuilder/morfeuszbuilder/segrules/rules.py       | 13 +++++++++++++
 fsabuilder/morfeuszbuilder/segrules/rulesParser.py | 18 +++++++++++++-----
 nbproject/configurations.xml                       |  6 ------
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/fsabuilder/morfeuszbuilder/segrules/rules.py b/fsabuilder/morfeuszbuilder/segrules/rules.py
index 89fc80d..5267ecb 100644
--- a/fsabuilder/morfeuszbuilder/segrules/rules.py
+++ b/fsabuilder/morfeuszbuilder/segrules/rules.py
@@ -43,6 +43,9 @@ class SegmentRule(object):
 
     def getAdditionalAtomicRules4Generator(self):
         raise NotImplementedError()
+    
+    def makeShiftOrthRule(self):
+        pass
 
     def __repr__(self):
         return str(self)
@@ -83,6 +86,9 @@ class TagRule(SegmentRule):
     
     def isShiftOrthRule(self):
         return self.shiftOrth
+    
+    def makeShiftOrthRule(self):
+        self.shiftOrth = True
 
     def getAtomicRules(self):
         yield self
@@ -101,6 +107,9 @@ class UnaryRule(SegmentRule):
     
     def isShiftOrthRule(self):
         return self.child.isShiftOrthRule()
+    
+    def makeShiftOrthRule(self):
+        self.child.makeShiftOrthRule()
 
     def getAtomicRules(self):
         for leaf in self.child.getAtomicRules():
@@ -127,6 +136,10 @@ class ComplexRule(SegmentRule):
         for child in self.children:
             for leaf in child.getAtomicRules():
                 yield leaf
+    
+    def makeShiftOrthRule(self):
+        for child in self.children:
+            child.makeShiftOrthRule()
 
 class ConcatRule(ComplexRule):
     
diff --git a/fsabuilder/morfeuszbuilder/segrules/rulesParser.py b/fsabuilder/morfeuszbuilder/segrules/rulesParser.py
index 611f56f..6e00b00 100644
--- a/fsabuilder/morfeuszbuilder/segrules/rulesParser.py
+++ b/fsabuilder/morfeuszbuilder/segrules/rulesParser.py
@@ -149,12 +149,17 @@ class RulesParser(object):
                                     ],
                                     lineNum)
     
+    def _createNewParenWithShiftOrthRule(self, rule, lineNum, line, segtypesHelper):
+        rule.makeShiftOrthRule()
+        return rule
+    
     def _doParseOneLine(self, lineNum, line, segtypesHelper, filename):
         rule = Forward()
         tagRule = Word(alphanums+'_')
         shiftOrthRule = Word(alphanums+'_') + Suppress('>')
         parenRule = Suppress('(') + rule + Suppress(')')
-        atomicRule = tagRule ^ shiftOrthRule ^ parenRule
+        parenWithShiftOrthRule = parenRule + Suppress('>')
+        atomicRule = tagRule ^ shiftOrthRule ^ parenWithShiftOrthRule ^ parenRule
         zeroOrMoreRule = atomicRule + Suppress('*')
         oneOrMoreRule = atomicRule + Suppress('+')
         optionalRule = atomicRule + Suppress('?')
@@ -169,11 +174,14 @@ class RulesParser(object):
 #             concatRule = OneOrMore(complexRule)
 #         else:
 #             concatRule = ZeroOrMore(shiftOrthRule) + tagRule
-        rule << concatRule + Optional(CaselessLiteral('!weak'))
+        
+        rule << concatRule
+        completeRule = rule + Optional(CaselessLiteral('!weak'))
         
         tagRule.setParseAction(lambda string, loc, toks: self._createNewTagRule(toks[0], False, lineNum, line, segtypesHelper))
         shiftOrthRule.setParseAction(lambda string, loc, toks: self._createNewTagRule(toks[0], True, lineNum, line, segtypesHelper))
-#         parenRule.setParseAction(lambda string, loc, toks: toks[0])
+        parenWithShiftOrthRule.setParseAction(lambda string, loc, toks: self._createNewParenWithShiftOrthRule(toks[0], lineNum, line, segtypesHelper))
+        parenRule.setParseAction(lambda string, loc, toks: toks[0])
         zeroOrMoreRule.setParseAction(lambda string, loc, toks: rules.ZeroOrMoreRule(toks[0], lineNum))
         quantRule1.setParseAction(lambda string, loc, toks: self._createQuantRule1(toks[0], int(toks[1], 10), lineNum, line, segtypesHelper))
         quantRule2.setParseAction(lambda string, loc, toks: self._createQuantRule2(toks[0], int(toks[1], 10), int(toks[2], 10), lineNum, line, segtypesHelper))
@@ -182,8 +190,8 @@ class RulesParser(object):
         oneOrMoreRule.setParseAction(lambda string, loc, toks: rules.ConcatRule([toks[0], rules.ZeroOrMoreRule(toks[0], lineNum)], lineNum))
         oneOfRule.setParseAction(lambda string, loc, toks: rules.OrRule(list(toks), lineNum))
         concatRule.setParseAction(lambda string, loc, toks: toks[0] if len(toks) == 1 else rules.ConcatRule(list(toks), lineNum))
-        rule.setParseAction(lambda string, loc, toks: toks[0].setWeak(len(toks) == 2))
-        parsedRule = pyparseString.pyparseString(rule, lineNum, line, filename)[0]
+        completeRule.setParseAction(lambda string, loc, toks: toks[0].setWeak(len(toks) == 2))
+        parsedRule = pyparseString.pyparseString(completeRule, lineNum, line, filename)[0]
 #         print parsedRule, '-->', parsedRule.transformToGeneratorVersion()
         return parsedRule
 
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 1cb702e..6de6dfa 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -859,22 +859,16 @@
             ex="false"
             tool="1"
             flavor2="4">
-        <ccTool flags="1">
-        </ccTool>
       </item>
       <item path="morfeusz/deserialization/morphInterps/InterpretedChunksDecoder4Analyzer.cpp"
             ex="false"
             tool="1"
             flavor2="4">
-        <ccTool flags="1">
-        </ccTool>
       </item>
       <item path="morfeusz/deserialization/morphInterps/InterpretedChunksDecoder4Generator.cpp"
             ex="false"
             tool="1"
             flavor2="4">
-        <ccTool flags="1">
-        </ccTool>
       </item>
       <item path="morfeusz/fsa/const.cpp" ex="false" tool="1" flavor2="4">
       </item>
--
libgit2 0.22.2