Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -138,20 +138,24 @@ # regex parser _, errs = _proofread(sText[iStart:iEnd], sRealText[iStart:iEnd], iStart, False, dDA, dPriority, sCountry, dOpt, bShowRuleId, bDebug, bContext) aErrors.update(errs) # token parser oSentence = TokenSentence(sText[iStart:iEnd], sRealText[iStart:iEnd], iStart) - bChange, errs = oSentence.parse(dPriority, sCountry, dOpt, bShowRuleId, True, bContext) + bChange, errs = oSentence.parse(dPriority, sCountry, dOpt, bShowRuleId, bDebug, bContext) aErrors.update(errs) if bChange: oSentence.rewrite() - if True: + if bDebug: print("~", oSentence.sSentence) except: raise return aErrors.values() # this is a view (iterable) + +_zEndOfSentence = re.compile(r'([.?!:;…][ .?!… »”")]*|.$)') +_zBeginOfParagraph = re.compile(r"^\W*") +_zEndOfParagraph = re.compile(r"\W*$") def _getSentenceBoundaries (sText): iStart = _zBeginOfParagraph.match(sText).end() for m in _zEndOfSentence.finditer(sText): yield (iStart, m.end()) @@ -376,18 +380,10 @@ return os.path.join(os.path.dirname(sys.modules[__name__].__file__), __name__ + ".py") #### common functions - -# common regexes -_zEndOfSentence = re.compile(r'([.?!:;…][ .?!… »”")]*|.$)') -_zBeginOfParagraph = re.compile(r"^\W*") -_zEndOfParagraph = re.compile(r"\W*$") -_zNextWord = re.compile(r" +(\w[\w-]*)") -_zPrevWord = re.compile(r"(\w[\w-]*) +$") - def option (sOpt): "return True if option sOpt is active" return _dOptions.get(sOpt, False) @@ -464,10 +460,13 @@ ## functions to get text outside pattern scope # warning: check compile_rules.py to understand how it works +_zNextWord = re.compile(r" +(\w[\w-]*)") +_zPrevWord = re.compile(r"(\w[\w-]*) +$") + def nextword (s, iStart, n): "get the nth word of the input string or empty string" m = re.match("(?: +[\\w%-]+){" + str(n-1) + "} +([\\w%-]+)", s[iStart:]) if not m: return None @@ -565,15 +564,10 @@ #### GRAMMAR CHECKER PLUGINS ${plugins} - -#### CALLABLES (generated code) - -${callables} - #### TOKEN SENTENCE CHECKER class TokenSentence: @@ -927,8 +921,13 @@ dToken["lMorph"] = lMorph #print("DA:", dToken["sValue"], lMorph) return True -#### CALLABLES (generated code) +#### CALLABLES FOR REGEX RULES (generated code) + +${callables} + + +#### CALLABLES FOR GRAPH RULES (generated code) ${graph_callables}