Overview
Comment: | [doc] update on syntax |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | doc |
Files: | files | file ages | folders |
SHA3-256: |
7b42dadf185b6c347ebcda4e718368d2 |
User & Date: | olr on 2017-06-07 07:31:06 |
Other Links: | manifest | tags |
Context
2017-06-07
| ||
07:37 | [core][fr] merge bookmark feature check-in: 72537ca8e8 user: olr tags: trunk, fr, core, new_feature | |
07:31 | [doc] update on syntax check-in: 7b42dadf18 user: olr tags: trunk, doc | |
2017-06-06
| ||
15:40 | [fr] pt: couleurs check-in: f2a7202993 user: olr tags: trunk, fr | |
Changes
Modified doc/syntax.txt from [4f6735223c] to [20a5f2bb94].
︙ | ︙ | |||
103 104 105 106 107 108 109 | Each rule name must be unique. The LCR flags are also optional. If you don’t set these flags, the default LCR flags will be: __[i]__ | | | | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | Each rule name must be unique. 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": foo <<- ->> bar # Use bar instead of foo. Example: Recognize and suggest missing hyphen and rewrite internally the text with the hyphen: __[s]__ foo bar <<- ->> foo-bar # Missing hyphen. <<- ~>> foo-bar |
︙ | ︙ | |||
150 151 152 153 154 155 156 | at the beginning of a line, the compiler won’t go further. Whatever is written after will be considered as comments. ## Whitespaces at the border of patterns or suggestions ## | | | | | | | | | > | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | at the beginning of a line, the compiler won’t go further. 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: __<s>__ " +" <<- ->> " " # Extra space(s). ASCII " characters protect spaces in the pattern and in the replacement text. ## 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: __<i]__ \b([?!.])([A-Z]+) <<- ->> \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: DEF: name pattern Usage in the rules: ({name}) (\w+) ->> "\1-\2" # Missing hyphen? ## Multiple suggestions ## Use | in the replacement text to add multiple suggestions: Example: Foo, FOO, Bar and BAR suggestions for the input word "foo". 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. foobar <<- ->> _ # Message ## Positioning ## Positioning is valid only for error creation and text rewriting. 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: (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: |
︙ | ︙ | |||
251 252 253 254 255 256 257 | <<- ->> \1s # Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun # Text rewriting # | | | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | <<- ->> \1s # Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun # Text rewriting # Example: Replacing a string by another 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. |
︙ | ︙ | |||
332 333 334 335 336 337 338 | these (\w+) <<- \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() | | | | | | | | | | | | | | | | | | | | | | | | | > > | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | these (\w+) <<- \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.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 Note: the analysis is done on the preprocessed text. ## Default variables ## `sCountry` It contains the current country locale of the checked paragraph. Example: colour <<- sCountry == "US" ->> color # Use American English spelling. # Expressions in the suggestions # |
︙ | ︙ | |||
430 431 432 433 434 435 436 437 438 439 440 441 442 443 | \w+ly <<- morph(\0, "adverb") ->> * 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 grammar mistakes can be detected with one simple rule: | > | 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | \w+ly <<- morph(\0, "adverb") ->> * 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 grammar mistakes can be detected with one simple rule: |
︙ | ︙ | |||
451 452 453 454 455 456 457 | 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. | | | < < < < | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | 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 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. == Pattern matching == Repeating pattern matching of a single rule continues after the previous matching, so instead of general multiword patterns, like (\w+) (\w+) <<- some_check(\1, \2) ->> \1, \2 # foo use (\w+) <<- some_check(\1, word(1)) ->> \1, # foo |