Index: doc/syntax.txt ================================================================== --- doc/syntax.txt +++ doc/syntax.txt @@ -105,15 +105,15 @@ The LCR flags are also optional. If you don’t set these flags, the default LCR flags will be: __[i]__ -Example. Report “foo” in the text and suggest "bar": +Example: Report “foo” in the text and suggest "bar": foo <<- ->> bar # Use bar instead of foo. -Example. Recognize and suggest missing hyphen and rewrite internally the text +Example: Recognize and suggest missing hyphen and rewrite internally the text with the hyphen: __[s]__ foo bar <<- ->> foo-bar # Missing hyphen. <<- ~>> foo-bar @@ -152,11 +152,11 @@ Whatever is written after will be considered as comments. ## Whitespaces at the border of patterns or suggestions ## -Example. Recognize double or more spaces and suggests a single space: +Example: Recognize double or more spaces and suggests a single space: ____ " +" <<- ->> " " # Extra space(s). ASCII " characters protect spaces in the pattern and in the replacement text. @@ -164,54 +164,54 @@ ## Pattern groups and back references ## It is usually useful to retrieve parts of the matched pattern. We simply use parenthesis in pattern to get groups with back references. -Example. Suggest a word with correct quotation marks: - -\"(\w+)\" <<- ->> “\1” # Correct quotation marks. - -Example. Suggest the missing space after the !, ? or . signs: - -__> \1 \2 # Missing space? - -Example. Back reference in messages. - -(fooo) bar <<- ->> foo bar # “\1” should be: +Example: Suggest a word with correct quotation marks: + + \"(\w+)\" <<- ->> “\1” # Correct quotation marks. + +Example: Suggest the missing space after the !, ? or . signs: + + __> \1 \2 # Missing space? + +Example: Back reference in messages. + + (fooo) bar <<- ->> foo bar # “\1” should be: ## Name definitions ## Grammalecte supports name definitions to simplify the description of the complex rules. -Example. +Example: DEF: name pattern Usage in the rules: -({name}) (\w+) ->> "\1-\2" # Missing hyphen? + ({name}) (\w+) ->> "\1-\2" # Missing hyphen? ## Multiple suggestions ## Use | in the replacement text to add multiple suggestions: -Example 7. Foo, FOO, Bar and BAR suggestions for the input word "foo". +Example: Foo, FOO, Bar and BAR suggestions for the input word "foo". -foo <<- ->> Foo|FOO|Bar|BAR # Did you mean: + foo <<- ->> Foo|FOO|Bar|BAR # Did you mean: ## No suggestion ## You can display message without making suggestions. For this purpose, use a single character _ in the suggestion field. -Example. No suggestion. +Example: No suggestion. -foobar <<- ->> _ # Message + foobar <<- ->> _ # Message ## Positioning ## Positioning is valid only for error creation and text rewriting. @@ -219,22 +219,23 @@ By default, the full pattern will be underlined with blue. You can shorten the underlined text area by specifying a back reference group of the pattern. Instead of writing ->>, write -n>> n being the number of a back reference group. Actually, ->> is similar to -0>> -Example. +Example: -(ying) and yang <<- -1>> yin # Did you mean: -__[s]__ (Mr.) [A-Z]\w+ <<- ~1>> Mr + (ying) and yang <<- -1>> yin # Did you mean: + + __[s]__ (Mr.) [A-Z]\w+ <<- ~1>> Mr ### Comparison ### Rule A: -ying and yang <<- ->> yin and yang # Did you mean: + ying and yang <<- ->> yin and yang # Did you mean: Rule B: -(ying) and yang <<- -1>> yin # Did you mean: + (ying) and yang <<- -1>> yin # Did you mean: With the rule A, the full pattern is underlined: ying and yang ^^^^^^^^^^^^^ @@ -245,21 +246,21 @@ ## Longer explanations with URLs ## Warning messages can contain optional URL for longer explanations separated by "|": -(your|her|our|their)['’]s - <<- ->> \1s - # Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun + (your|her|our|their)['’]s + <<- ->> \1s + # Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun # Text rewriting # -Example. Replacing a string by another +Example: Replacing a string by another -Mr. [A-Z]\w+ <<- ~>> Mister + Mr. [A-Z]\w+ <<- ~>> Mister WARNING: The replacing text must be shorter than the replaced text or have the same length. Breaking this rule will misplace following error reports. You have to ensure yourself the rules comply with this constraint, Grammalecte won’t do it for you. @@ -274,15 +275,15 @@ check usage of punctuations and whitespaces. @ are automatically removed at the beginning of the second pass. You can use positioning with text rewriting actions. -Mr(. [A-Z]\w+) <<- ~1>> * + Mr(. [A-Z]\w+) <<- ~1>> * You can also call Python expressions. -__[s]__ Mr. ([a-z]\w+) <<- ~1>> =\1.upper() + __[s]__ Mr. ([a-z]\w+) <<- ~1>> =\1.upper() # Disambiguation # @@ -334,56 +335,58 @@ <<- \1 == "man" -1>> men # Man is a singular noun. Use the plural form: You can also apply functions to subgroups like: \1.startswith("a") \3.islower() - re.match("pattern", \2) + re.search("pattern", \2) … ## Standard functions ## -word(n) - catches the nth next word after the pattern (separated only by white spaces). - returns None if no word catched - -word(-n) - catches the nth next word before the pattern (separated only by white spaces). - returns None if no word catched - -after(regex[, neg_regex]) - checks if the text after the pattern matches the regex. - -before(regex[, neg_regex]) - checks if the text before the pattern matches the regex. - -textarea(regex[, neg_regex]) - checks if the full text of the checked area (paragraph or sentence) matches the regex. - -morph(n, regex[, strict=True][, noword=False]) - checks if all tags of the word in group n match the regex. - if strict = False, returns True only if one of tags matches the regex. - if there is no word at position n, returns the value of noword. - -morphex(n, regex, neg_regex[, noword=False]) - checks if one of the tags of the word in group n match the regex and - if no tags matches the neg_regex. - if there is no word at position n, returns the value of noword. - -option(option_name) - returns True if option_name is activated else False +`word(n)` +> catches the nth next word after the pattern (separated only by white spaces). +> returns None if no word catched + +`word(-n)` +> catches the nth next word before the pattern (separated only by white spaces). +> returns None if no word catched + +`after(regex[, neg_regex])` +> checks if the text after the pattern matches the regex. + +`before(regex[, neg_regex])` +> checks if the text before the pattern matches the regex. + +`textarea(regex[, neg_regex])` +> checks if the full text of the checked area (paragraph or sentence) matches the regex. + +`morph(n, regex[, strict=True][, noword=False])` +> checks if all tags of the word in group n match the regex. +> if strict = False, returns True only if one of tags matches the regex. +> if there is no word at position n, returns the value of noword. + +`morphex(n, regex, neg_regex[, noword=False])` +> checks if one of the tags of the word in group n match the regex and +> if no tags matches the neg_regex. +> if there is no word at position n, returns the value of noword. + +`option(option_name)` +> returns True if option_name is activated else False Note: the analysis is done on the preprocessed text. ## Default variables ## -sCountry +`sCountry` It contains the current country locale of the checked paragraph. -colour <<- sCountry == "US" ->> color # Use American English spelling. +Example: + + colour <<- sCountry == "US" ->> color # Use American English spelling. # Expressions in the suggestions # @@ -390,11 +393,11 @@ Suggestions (and warning messages) started by an equal sign are Python string expressions extended with possible back references and named definitions: Example: -foo\w+ ->> = '"' + \0.upper() + '"' # With uppercase letters and quoation marks + foo\w+ ->> = '"' + \0.upper() + '"' # With uppercase letters and quoation marks All words beginning with "foo" will be recognized, and the suggestion is the uppercase form of the string with ASCII quoation marks: eg. foom ->> "FOOM". @@ -432,43 +435,40 @@ You can also remove a group reference: these (\w+) (\w+) <<- morph(\1, "adjective") and morph(\2, "noun") -1>> * (am|are|is|were|was) (all) -2>> * With these rules, you get the following sentences: -These cats are blacks. -These cats are blacks . -These cats are blacks. -These cats are blacks. -These cats are blacks. + + These cats are blacks. + These cats are blacks . + These cats are blacks. + These cats are blacks. + These cats are blacks. These grammar mistakes can be detected with one simple rule: -these +(\w+) +are +(\w+s) - <<- morph(\1, "noun") and morph(\2, "plural") - -2>> _ # Adjectives are invariable. + these +(\w+) +are +(\w+s) + <<- morph(\1, "noun") and morph(\2, "plural") + -2>> _ # Adjectives are invariable. Instead of replacing text with whitespaces, you can replace text with @. -https?://\S+ ->> @ + https?://\S+ ->> @ This is useful if at first pass you write rules to check successive whitespaces. @ are automatically removed at the second pass. You can also replace any text as you wish. -Mister ->> Mr -(Mrs?)[.] ->> \1 + Mister <<- ->> Mr + (Mrs?)[.] <<- ->> \1 With the multi-passes checking and the text preprocessor, it is advised to remove or simplify the text which has been checked on the previous pass. - - -= Typical problems = - == Pattern matching == Repeating pattern matching of a single rule continues after the previous matching, so