summary refs log tree commit diff stats
path: root/lib/pure/logging.nim
Commit message (Expand)AuthorAgeFilesLines
* Enabled logging tests for jsYuriy Glukhov2016-09-031-4/+5
* Logging compatible with jsYuriy Glukhov2016-09-031-111/+124
* prepare Nim codebase for upcoming parser changesAndreas Rumpf2016-07-151-1/+1
* pure/logging: add notice level, suggest usecasesniv2016-05-011-1/+27
* respect global log filter levelBruce Doan2015-11-281-6/+7
* logging.nim: expose underlying 'file' object; errors and fatals flush the buf...Araq2015-10-121-10/+13
* Add substituteLog docsFederico Ceratto2015-10-091-0/+2
* Export substituteLogFederico Ceratto2015-10-091-1/+1
* renamed writeln to writeLine in libpatrick dw2015-06-191-3/+3
* Fix logger formattingSergey Avseyev2015-06-131-11/+20
* Merge pull request #2830 from yglukhov/logging-no-formatDominik Picheta2015-06-041-30/+22
|\
| * Removed formatting from logging.yglukhov2015-05-281-30/+22
* | Documented bufSize param in logging.nimx2f2015-06-011-1/+5
* | Expose bufSize parameter for file-based loggersx2f2015-05-311-5/+9
|/
* logging: make fmtStr public to be used in user defined loggersFrank Fischer2015-05-111-1/+1
* Don't run non-test code when defined(testing)Oleh Prypin2015-04-211-1/+1
* Use `^` instead of `-` in slicesdef2015-03-281-34/+34
* fixed log*(logger: RollingFileLogger, level: Level,teroz2015-03-131-1/+1
* Fix typosFederico Ceratto2015-02-151-1/+1
* newRollingFileLogger - fmtStr is always set to defaultFmtStrFabio Cevasco2015-02-061-1/+1
* Logging module is now thread-safe.Dominik Picheta2015-01-251-9/+27
* Happy new year!Guillaume Gelin2015-01-061-1/+1
* docgen should work againAraq2014-10-051-1/+4
* more modules updatedAraq2014-08-281-20/+20
* big renameAraq2014-08-271-14/+17
* Fixes docgen for logging module.Dominik Picheta2014-02-021-2/+2
* Finished logging module.Dominik Picheta2014-01-271-0/+267
* tests are green againAraq2011-06-281-144/+0
* little repo cleanupAraq2011-05-021-5/+3
* bugfix: times.epochTimeAraq2011-04-251-2/+2
* cleanup: E_Base should not be used for inheriting exceptions; documentation g...Araq2011-01-151-1/+1
* fixed pango/pangoutils new wrappersAndreas Rumpf2010-02-261-0/+0
* continued work on html/xmlparserrumpf_a@web.de2010-02-141-0/+0
* better subscript overloadingrumpf_a@web.de2010-01-031-0/+146
possibly consumes some text. Indicate success if one of expressions succeeded. Otherwise do not consume any text and indicate failure. ``A ... Z`` Sequence: Apply expressions `A`, ..., `Z`, in this order, to consume consecutive portions of the text ahead, as long as they succeed. Indicate success if all succeeded. Otherwise do not consume any text and indicate failure. The sequence's precedence is higher than that of ordered choice: ``A B / C`` means ``(A B) / Z`` and not ``A (B / Z)``. ``(E)`` Grouping: Parenthesis can be used to change operator priority. ``{E}`` Capture: Apply expression `E` and store the substring that matched `E` into a *capture* that can be accessed after the matching process. ``$i`` Back reference to the ``i``th capture. ``i`` counts from 1. ``$`` Anchor: Matches at the end of the input. No character is consumed. Same as ``!.``. ``^`` Anchor: Matches at the start of the input. No character is consumed. ``&E`` And predicate: Indicate success if expression `E` matches the text ahead; otherwise indicate failure. Do not consume any text. ``!E`` Not predicate: Indicate failure if expression E matches the text ahead; otherwise indicate success. Do not consume any text. ``E+`` One or more: Apply expression `E` repeatedly to match the text ahead, as long as it succeeds. Consume the matched text (if any) and indicate success if there was at least one match. Otherwise indicate failure. ``E*`` Zero or more: Apply expression `E` repeatedly to match the text ahead, as long as it succeeds. Consume the matched text (if any). Always indicate success. ``E?`` Zero or one: If expression `E` matches the text ahead, consume it. Always indicate success. ``[s]`` Character class: If the character ahead appears in the string `s`, consume it and indicate success. Otherwise indicate failure. ``[a-b]`` Character range: If the character ahead is one from the range `a` through `b`, consume it and indicate success. Otherwise indicate failure. ``'s'`` String: If the text ahead is the string `s`, consume it and indicate success. Otherwise indicate failure. ``i's'`` String match ignoring case. ``y's'`` String match ignoring style. ``v's'`` Verbatim string match: Use this to override a global ``\i`` or ``\y`` modifier. ``i$j`` String match ignoring case for back reference. ``y$j`` String match ignoring style for back reference. ``v$j`` Verbatim string match for back reference. ``.`` Any character: If there is a character ahead, consume it and indicate success. Otherwise (that is, at the end of input) indicate failure. ``_`` Any Unicode character: If there is an UTF-8 character ahead, consume it and indicate success. Otherwise indicate failure. ``@E`` Search: Shorthand for ``(!E .)* E``. (Search loop for the pattern `E`.) ``{@} E`` Captured Search: Shorthand for ``{(!E .)*} E``. (Search loop for the pattern `E`.) Everything until and exluding `E` is captured. ``@@ E`` Same as ``{@} E``. ``A <- E`` Rule: Bind the expression `E` to the *nonterminal symbol* `A`. **Left recursive rules are not possible and crash the matching engine.** ``\identifier`` Built-in macro for a longer expression. ``\ddd`` Character with decimal code *ddd*. ``\"``, etc Literal ``"``, etc. =============== ============================================================ Built-in macros --------------- ============== ============================================================ macro meaning ============== ============================================================ ``\d`` any decimal digit: ``[0-9]`` ``\D`` any character that is not a decimal digit: ``[^0-9]`` ``\s`` any whitespace character: ``[ \9-\13]`` ``\S`` any character that is not a whitespace character: ``[^ \9-\13]`` ``\w`` any "word" character: ``[a-zA-Z0-9_]`` ``\W`` any "non-word" character: ``[^a-zA-Z0-9_]`` ``\a`` same as ``[a-zA-Z]`` ``\A`` same as ``[^a-zA-Z]`` ``\n`` any newline combination: ``\10 / \13\10 / \13`` ``\i`` ignore case for matching; use this at the start of the PEG ``\y`` ignore style for matching; use this at the start of the PEG ``\skip`` pat skip pattern *pat* before trying to match other tokens; this is useful for whitespace skipping, for example: ``\skip(\s*) {\ident} ':' {\ident}`` matches key value pairs ignoring whitespace around the ``':'``. ``\ident`` a standard ASCII identifier: ``[a-zA-Z_][a-zA-Z_0-9]*`` ``\letter`` any Unicode letter ``\upper`` any Unicode uppercase letter ``\lower`` any Unicode lowercase letter ``\title`` any Unicode title letter ``\white`` any Unicode whitespace character ============== ============================================================ A backslash followed by a letter is a built-in macro, otherwise it is used for ordinary escaping: ============== ============================================================ notation meaning ============== ============================================================ ``\\`` a single backslash ``\*`` same as ``'*'`` ``\t`` not a tabulator, but an (unknown) built-in ============== ============================================================ Supported PEG grammar --------------------- The PEG parser implements this grammar (written in PEG syntax):: # Example grammar of PEG in PEG syntax. # Comments start with '#'. # First symbol is the start symbol. grammar <- rule* / expr identifier <- [A-Za-z][A-Za-z0-9_]* charsetchar <- "\\" . / [^\]] charset <- "[" "^"? (charsetchar ("-" charsetchar)?)+ "]" stringlit <- identifier? ("\"" ("\\" . / [^"])* "\"" / "'" ("\\" . / [^'])* "'") builtin <- "\\" identifier / [^\13\10] comment <- '#' @ \n ig <- (\s / comment)* # things to ignore rule <- identifier \s* "<-" expr ig identNoArrow <- identifier !(\s* "<-") prefixOpr <- ig '&' / ig '!' / ig '@' / ig '{@}' / ig '@@' literal <- ig identifier? '$' [0-9]+ / '$' / '^' / ig identNoArrow / ig charset / ig stringlit / ig builtin / ig '.' / ig '_' / (ig "(" expr ig ")") postfixOpr <- ig '?' / ig '*' / ig '+' primary <- prefixOpr* (literal postfixOpr*) # Concatenation has higher priority than choice: # ``a b / c`` means ``(a b) / c`` seqExpr <- primary+ expr <- seqExpr (ig "/" expr)* **Note**: As a special syntactic extension if the whole PEG is only a single expression, identifiers are not interpreted as non-terminals, but are interpreted as verbatim string: .. code-block:: nimrod abc =~ peg"abc" # is true So it is not necessary to write ``peg" 'abc' "`` in the above example. Examples -------- Check if `s` matches Nimrod's "while" keyword: .. code-block:: nimrod s =~ peg" y'while'" Exchange (key, val)-pairs: .. code-block:: nimrod "key: val; key2: val2".replace(peg"{\ident} \s* ':' \s* {\ident}", "$2: $1") Determine the ``#include``'ed files of a C file: .. code-block:: nimrod for line in lines("myfile.c"): if line =~ peg"""s <- ws '#include' ws '"' {[^"]+} '"' ws comment <- '/*' @ '*/' / '//' .* ws <- (comment / \s+)* """: echo matches[0] PEG vs regular expression ------------------------- As a regular expression ``\[.*\]`` matches the longest possible text between ``'['`` and ``']'``. As a PEG it never matches anything, because a PEG is deterministic: ``.*`` consumes the rest of the input, so ``\]`` never matches. As a PEG this needs to be written as: ``\[ ( !\] . )* \]`` (or ``\[ @ \]``). Note that the regular expression does not behave as intended either: in the example ``*`` should not be greedy, so ``\[.*?\]`` should be used instead. PEG construction ---------------- There are two ways to construct a PEG in Nimrod code: (1) Parsing a string into an AST which consists of `TPeg` nodes with the `peg` proc. (2) Constructing the AST directly with proc calls. This method does not support constructing rules, only simple expressions and is not as convenient. Its only advantage is that it does not pull in the whole PEG parser into your executable.