The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit c5266e7d authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

rebuilt documentation

parent a4f717ba
This diff is collapsed.
......@@ -25,25 +25,17 @@
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="DHParser 0.8 documentation" href="../index.html"/>
<link rel="up" title="Module code" href="index.html"/>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
......@@ -102,7 +94,7 @@
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">DHParser</a>
......@@ -110,9 +102,10 @@
</nav>
<div class="wy-nav-content">
<div class="rst-content">
......@@ -142,8 +135,6 @@
<li class="wy-breadcrumbs-aside">
</li>
</ul>
......@@ -195,7 +186,7 @@
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">DHParser.preprocess</span> <span class="k">import</span> <span class="n">strip_tokens</span><span class="p">,</span> <span class="n">with_source_mapping</span><span class="p">,</span> <span class="n">PreprocessorFunc</span>
<span class="kn">from</span> <span class="nn">DHParser.syntaxtree</span> <span class="k">import</span> <span class="n">Node</span>
<span class="kn">from</span> <span class="nn">DHParser.syntaxtree</span> <span class="k">import</span> <span class="n">Node</span><span class="p">,</span> <span class="n">RootNode</span>
<span class="kn">from</span> <span class="nn">DHParser.transform</span> <span class="k">import</span> <span class="n">TransformationFunc</span>
<span class="kn">from</span> <span class="nn">DHParser.parse</span> <span class="k">import</span> <span class="n">Grammar</span>
<span class="kn">from</span> <span class="nn">DHParser.error</span> <span class="k">import</span> <span class="n">adjust_error_locations</span><span class="p">,</span> <span class="n">is_error</span><span class="p">,</span> <span class="n">Error</span>
......@@ -251,10 +242,11 @@
<span class="bp">self</span><span class="o">.</span><span class="n">set_grammar_name</span><span class="p">(</span><span class="n">grammar_name</span><span class="p">,</span> <span class="n">grammar_source</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tree</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># type: Optional[RootNode]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># type: List[Node]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_dirty_flag</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">:</span> <span class="n">Node</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">root</span><span class="p">:</span> <span class="n">RootNode</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compiles the abstract syntax tree with the root node `node` and</span>
<span class="sd"> returns the compiled code. It is up to subclasses implementing</span>
......@@ -265,37 +257,38 @@
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dirty_flag</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_reset</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_dirty_flag</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">propagate_error_flags</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">lazy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tree</span> <span class="o">=</span> <span class="n">root</span>
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
<span class="k">return</span> <span class="n">result</span>
<div class="viewcode-block" id="Compiler.set_grammar_name"><a class="viewcode-back" href="../ModuleReference.html#compile.Compiler.set_grammar_name">[docs]</a> <span class="k">def</span> <span class="nf">set_grammar_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">grammar_name</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">grammar_source</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<div class="viewcode-block" id="Compiler.set_grammar_name"><a class="viewcode-back" href="../ModuleReference.html#compile.Compiler.set_grammar_name">[docs]</a> <span class="k">def</span> <span class="nf">set_grammar_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">grammar_name</span><span class="p">:</span> <span class="nb">str</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">grammar_source</span><span class="p">:</span> <span class="nb">str</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Changes the grammar&#39;s name and the grammar&#39;s source.</span>
<span class="sd"> The grammar name and the source text of the grammar are</span>
<span class="sd"> metadata about the grammar that do not affect the compilation</span>
<span class="sd"> process. Classes inheriting from `Compiler` can use this</span>
<span class="sd"> information to name and annotate its output.</span>
<span class="sd"> information to name and annotate its output. Returns `self`.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">assert</span> <span class="n">grammar_name</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;\w+\Z&#39;</span><span class="p">,</span> <span class="n">grammar_name</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">grammar_name</span> <span class="ow">and</span> <span class="n">re</span><span class="o">.</span><span class="n">fullmatch</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;[\w/:</span><span class="se">\\</span><span class="s1">]+&#39;</span><span class="p">,</span> <span class="n">grammar_source</span><span class="p">):</span>
<span class="n">grammar_name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">grammar_source</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">grammar_name</span> <span class="o">=</span> <span class="n">grammar_name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">grammar_source</span> <span class="o">=</span> <span class="n">load_if_file</span><span class="p">(</span><span class="n">grammar_source</span><span class="p">)</span></div>
<div class="viewcode-block" id="Compiler.propagate_error_flags"><a class="viewcode-back" href="../ModuleReference.html#compile.Compiler.propagate_error_flags">[docs]</a> <span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">propagate_error_flags</span><span class="p">(</span><span class="n">node</span><span class="p">:</span> <span class="n">Node</span><span class="p">,</span> <span class="n">lazy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># See test_parser.TestCompilerClass.test_propagate_error()..</span>
<span class="sd">&quot;&quot;&quot;Propagates error flags from children to parent nodes to make sure</span>
<span class="sd"> that the parent&#39;s error flag is always greater or equal the maximum</span>
<span class="sd"> of the children&#39;s error flags.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">lazy</span> <span class="ow">or</span> <span class="n">node</span><span class="o">.</span><span class="n">error_flag</span> <span class="o">&lt;</span> <span class="n">Error</span><span class="o">.</span><span class="n">HIGHEST</span><span class="p">:</span>
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
<span class="n">Compiler</span><span class="o">.</span><span class="n">propagate_error_flags</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">error_flag</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">error_flag</span><span class="p">,</span> <span class="n">child</span><span class="o">.</span><span class="n">error_flag</span><span class="p">)</span>
<span class="k">if</span> <span class="n">lazy</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">error_flag</span> <span class="o">&gt;=</span> <span class="n">Error</span><span class="o">.</span><span class="n">HIGHEST</span><span class="p">:</span>
<span class="k">return</span></div>
<span class="bp">self</span><span class="o">.</span><span class="n">grammar_source</span> <span class="o">=</span> <span class="n">load_if_file</span><span class="p">(</span><span class="n">grammar_source</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span></div>
<span class="c1"># @staticmethod</span>
<span class="c1"># def propagate_error_flags(node: Node, lazy: bool = True) -&gt; None:</span>
<span class="c1"># # See test_parser.TestCompilerClass.test_propagate_error()..</span>
<span class="c1"># &quot;&quot;&quot;Propagates error flags from children to parent nodes to make sure</span>
<span class="c1"># that the parent&#39;s error flag is always greater or equal the maximum</span>
<span class="c1"># of the children&#39;s error flags.&quot;&quot;&quot;</span>
<span class="c1"># if not lazy or node.error_flag &lt; Error.HIGHEST:</span>
<span class="c1"># for child in node.children:</span>
<span class="c1"># Compiler.propagate_error_flags(child)</span>
<span class="c1"># node.error_flag = max(node.error_flag, child.error_flag)</span>
<span class="c1"># if lazy and node.error_flag &gt;= Error.HIGHEST:</span>
<span class="c1"># return</span>
<div class="viewcode-block" id="Compiler.method_name"><a class="viewcode-back" href="../ModuleReference.html#compile.Compiler.method_name">[docs]</a> <span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">method_name</span><span class="p">(</span><span class="n">node_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
......@@ -404,28 +397,27 @@
<span class="c1"># only compile if there were no syntax errors, for otherwise it is</span>
<span class="c1"># likely that error list gets littered with compile error messages</span>
<span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">efl</span> <span class="o">=</span> <span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span>
<span class="n">messages</span> <span class="o">=</span> <span class="n">syntax_tree</span><span class="o">.</span><span class="n">collect_errors</span><span class="p">(</span><span class="n">clear_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">is_error</span><span class="p">(</span><span class="n">efl</span><span class="p">):</span>
<span class="c1"># efl = syntax_tree.error_flag</span>
<span class="c1"># messages = syntax_tree.collect_errors(clear_errors=True)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">is_error</span><span class="p">(</span><span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span><span class="p">):</span>
<span class="n">transformer</span><span class="p">(</span><span class="n">syntax_tree</span><span class="p">)</span>
<span class="n">efl</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">efl</span><span class="p">,</span> <span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span><span class="p">)</span>
<span class="n">messages</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">syntax_tree</span><span class="o">.</span><span class="n">collect_errors</span><span class="p">(</span><span class="n">clear_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="c1"># efl = max(efl, syntax_tree.error_flag)</span>
<span class="c1"># messages.extend(syntax_tree.collect_errors(clear_errors=True))</span>
<span class="k">if</span> <span class="n">is_logging</span><span class="p">():</span>
<span class="n">log_ST</span><span class="p">(</span><span class="n">syntax_tree</span><span class="p">,</span> <span class="n">log_file_name</span> <span class="o">+</span> <span class="s1">&#39;.ast&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">is_error</span><span class="p">(</span><span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span><span class="p">):</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">compiler</span><span class="p">(</span><span class="n">syntax_tree</span><span class="p">)</span>
<span class="c1"># print(syntax_tree.as_sxpr())</span>
<span class="n">messages</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">syntax_tree</span><span class="o">.</span><span class="n">collect_errors</span><span class="p">())</span>
<span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">syntax_tree</span><span class="o">.</span><span class="n">error_flag</span><span class="p">,</span> <span class="n">efl</span><span class="p">)</span>
<span class="c1"># messages.extend(syntax_tree.collect_errors())</span>
<span class="c1"># syntax_tree.error_flag = max(syntax_tree.error_flag, efl)</span>
<span class="n">messages</span> <span class="o">=</span> <span class="n">syntax_tree</span><span class="o">.</span><span class="n">collect_errors</span><span class="p">()</span>
<span class="n">adjust_error_locations</span><span class="p">(</span><span class="n">messages</span><span class="p">,</span> <span class="n">original_text</span><span class="p">,</span> <span class="n">source_mapping</span><span class="p">)</span>
<span class="k">return</span> <span class="n">result</span><span class="p">,</span> <span class="n">messages</span><span class="p">,</span> <span class="n">syntax_tree</span></div>
</pre></div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
......@@ -438,7 +430,7 @@
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
......@@ -457,6 +449,7 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'0.8',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
......@@ -475,14 +468,13 @@
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
SphinxRtdTheme.Navigation.enableSticky();
});
</script>
</script>
</body>
</html>
\ No newline at end of file
......@@ -25,25 +25,17 @@
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="DHParser 0.8 documentation" href="../index.html"/>
<link rel="up" title="Module code" href="index.html"/>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
......@@ -102,7 +94,7 @@
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">DHParser</a>
......@@ -110,9 +102,10 @@
</nav>
<div class="wy-nav-content">
<div class="rst-content">
......@@ -142,8 +135,6 @@
<li class="wy-breadcrumbs-aside">
</li>
</ul>
......@@ -237,18 +228,18 @@
<span class="s1">import os</span>
<span class="s1">import sys</span>
<span class="s1">sys.path.append(&#39;</span><span class="si">{dhparserdir}</span><span class="s1">&#39;)</span>
<span class="s1">sys.path.append(r&#39;</span><span class="si">{dhparserdir}</span><span class="s1">&#39;)</span>
<span class="s1">try:</span>
<span class="s1"> import regex as re</span>
<span class="s1">except ImportError:</span>
<span class="s1"> import re</span>
<span class="s1">from DHParser import logging, is_filename, load_if_file, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> Grammar, Compiler, nil_preprocessor, PreprocessorToken, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> Grammar, Compiler, nil_preprocessor, PreprocessorToken, Whitespace, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> Lookbehind, Lookahead, Alternative, Pop, Token, Synonym, AllOf, SomeOf, Unordered, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> Option, NegativeLookbehind, OneOrMore, RegExp, Retrieve, Series, RE, Capture, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> ZeroOrMore, Forward, NegativeLookahead, mixin_comment, compile_source, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> last_value, counterpart, accumulate, PreprocessorFunc, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> ZeroOrMore, Forward, NegativeLookahead, Required, mixin_comment, compile_source, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> grammar_changed, last_value, counterpart, accumulate, PreprocessorFunc, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> Node, TransformationFunc, TransformationDict, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> traverse, remove_children_if, merge_children, is_anonymous, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> reduce_single_child, replace_by_single_child, replace_or_reduce, remove_whitespace, </span><span class="se">\\</span><span class="s1"></span>
......@@ -256,7 +247,7 @@
<span class="s1"> is_empty, is_expendable, collapse, replace_content, WHITESPACE_PTYPE, TOKEN_PTYPE, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> remove_nodes, remove_content, remove_brackets, replace_parser, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> keep_children, is_one_of, has_content, apply_if, remove_first, remove_last, </span><span class="se">\\</span><span class="s1"></span>
<span class="s1"> remove_anonymous_empty, keep_nodes, traverse_locally, strip</span>
<span class="s1"> remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip</span>
<span class="s1">&#39;&#39;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dhparserdir</span><span class="o">=</span><span class="n">dhparserdir</span><span class="p">)</span>
......@@ -277,6 +268,14 @@
<span class="s1">if __name__ == &quot;__main__&quot;:</span>
<span class="s1"> if len(sys.argv) &gt; 1:</span>
<span class="s1"> try:</span>
<span class="s1"> grammar_file_name = os.path.basename(__file__).replace(&#39;Compiler.py&#39;, &#39;.ebnf&#39;)</span>
<span class="s1"> if grammar_changed(</span><span class="si">{NAME}</span><span class="s1">Grammar, grammar_file_name):</span>
<span class="s1"> print(&quot;Grammar has changed. Please recompile Grammar first.&quot;)</span>
<span class="s1"> sys.exit(1)</span>
<span class="s1"> except FileNotFoundError:</span>
<span class="s1"> print(&#39;Could not check for changed grammar, because grammar file &quot;</span><span class="si">%s</span><span class="s1">&quot; was not found!&#39;</span>
<span class="s1"> </span><span class="si">% g</span><span class="s1">rammar_file_name) </span>
<span class="s1"> file_name, log_dir = sys.argv[1], &#39;&#39;</span>
<span class="s1"> if file_name in [&#39;-d&#39;, &#39;--debug&#39;] and len(sys.argv) &gt; 2:</span>
<span class="s1"> file_name, log_dir = sys.argv[2], &#39;LOGS&#39;</span>
......@@ -460,8 +459,10 @@
<span class="sd"> language defined by ``ebnf_src``.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">grammar_src</span> <span class="o">=</span> <span class="n">compileDSL</span><span class="p">(</span><span class="n">ebnf_src</span><span class="p">,</span> <span class="n">nil_preprocessor</span><span class="p">,</span> <span class="n">get_ebnf_grammar</span><span class="p">(),</span>
<span class="n">get_ebnf_transformer</span><span class="p">(),</span> <span class="n">get_ebnf_compiler</span><span class="p">(</span><span class="n">branding</span><span class="p">))</span>
<span class="k">return</span> <span class="n">compile_python_object</span><span class="p">(</span><span class="n">DHPARSER_IMPORTS</span> <span class="o">+</span> <span class="n">grammar_src</span><span class="p">,</span> <span class="sa">r</span><span class="s1">&#39;get_(?:\w+_)?grammar$&#39;</span><span class="p">)</span></div>
<span class="n">get_ebnf_transformer</span><span class="p">(),</span> <span class="n">get_ebnf_compiler</span><span class="p">(</span><span class="n">branding</span><span class="p">,</span> <span class="n">ebnf_src</span><span class="p">))</span>
<span class="n">grammar_obj</span> <span class="o">=</span> <span class="n">compile_python_object</span><span class="p">(</span><span class="n">DHPARSER_IMPORTS</span> <span class="o">+</span> <span class="n">grammar_src</span><span class="p">,</span> <span class="sa">r</span><span class="s1">&#39;get_(?:\w+_)?grammar$&#39;</span><span class="p">)</span>
<span class="n">grammar_obj</span><span class="o">.</span><span class="n">python_src__</span> <span class="o">=</span> <span class="n">grammar_src</span>
<span class="k">return</span> <span class="n">grammar_obj</span></div>
<div class="viewcode-block" id="load_compiler_suite"><a class="viewcode-back" href="../ModuleReference.html#dsl.load_compiler_suite">[docs]</a><span class="k">def</span> <span class="nf">load_compiler_suite</span><span class="p">(</span><span class="n">compiler_suite</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> \
......@@ -472,7 +473,8 @@
<span class="sd"> and returns it as a tuple (preprocessor, parser, ast, compiler).</span>
<span class="sd"> Returns:</span>
<span class="sd"> 4-tuple (preprocessor function, parser class, ast transformer function, compiler class)</span>
<span class="sd"> 4-tuple (preprocessor function, parser class,</span>
<span class="sd"> ast transformer function, compiler class)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">global</span> <span class="n">RX_SECTION_MARKER</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">compiler_suite</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span>
......@@ -495,7 +497,8 @@
<span class="c1"># Is there really any reasonable application case for this?</span>
<span class="k">with</span> <span class="n">logging</span><span class="p">(</span><span class="kc">False</span><span class="p">):</span>
<span class="n">compiler_py</span><span class="p">,</span> <span class="n">messages</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">compile_source</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">get_ebnf_grammar</span><span class="p">(),</span>
<span class="n">get_ebnf_transformer</span><span class="p">(),</span> <span class="n">get_ebnf_compiler</span><span class="p">())</span>
<span class="n">get_ebnf_transformer</span><span class="p">(),</span>
<span class="n">get_ebnf_compiler</span><span class="p">(</span><span class="n">compiler_suite</span><span class="p">,</span> <span class="n">source</span><span class="p">))</span>
<span class="k">if</span> <span class="n">has_errors</span><span class="p">(</span><span class="n">messages</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">GrammarError</span><span class="p">(</span><span class="n">only_errors</span><span class="p">(</span><span class="n">messages</span><span class="p">),</span> <span class="n">source</span><span class="p">)</span>
<span class="n">preprocessor</span> <span class="o">=</span> <span class="n">get_ebnf_preprocessor</span>
......@@ -740,9 +743,7 @@
</pre></div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
......@@ -755,7 +756,7 @@
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
......@@ -774,6 +775,7 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'0.8',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
......@@ -792,14 +794,13 @@
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
SphinxRtdTheme.Navigation.enableSticky();
});
</script>
</script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
......@@ -25,25 +25,17 @@
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="DHParser 0.8 documentation" href="../index.html"/>
<link rel="up" title="Module code" href="index.html"/>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
......@@ -102,7 +94,7 @@
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">DHParser</a>
......@@ -110,9 +102,10 @@
</nav>
<div class="wy-nav-content">
<div class="rst-content">
......@@ -142,8 +135,6 @@
<li class="wy-breadcrumbs-aside">
</li>
</ul>
......@@ -198,7 +189,7 @@
<span class="kn">from</span> <span class="nn">DHParser.preprocess</span> <span class="k">import</span> <span class="n">SourceMapFunc</span>
<span class="kn">from</span> <span class="nn">DHParser.stringview</span> <span class="k">import</span> <span class="n">StringView</span>
<span class="kn">from</span> <span class="nn">DHParser.toolkit</span> <span class="k">import</span> <span class="n">typing</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">Iterable</span><span class="p">,</span> <span class="n">Iterator</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">List</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">Iterable</span><span class="p">,</span> <span class="n">Iterator</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;Error&#39;</span><span class="p">,</span>
<span class="s1">&#39;is_error&#39;</span><span class="p">,</span>
......@@ -211,11 +202,13 @@
<span class="k">class</span> <span class="nc">Error</span><span class="p">:</span>
<span class="vm">__slots__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;message&#39;</span><span class="p">,</span> <span class="s1">&#39;level&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;pos&#39;</span><span class="p">,</span> <span class="s1">&#39;orig_pos&#39;</span><span class="p">,</span> <span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="s1">&#39;column&#39;</span><span class="p">]</span>
<span class="vm">__slots__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;message&#39;</span><span class="p">,</span> <span class="s1">&#39;level&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;_pos&#39;</span><span class="p">,</span> <span class="s1">&#39;orig_pos&#39;</span><span class="p">,</span> <span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="s1">&#39;column&#39;</span><span class="p">,</span> <span class="s1">&#39;_node_keep&#39;</span><span class="p">]</span>
<span class="c1"># error levels</span>
<span class="n">WARNING</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">NO_ERROR</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">MESSAGE</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">WARNING</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">ERROR</span> <span class="o">=</span> <span class="mi">1000</span>
<span class="n">HIGHEST</span> <span class="o">=</span> <span class="n">ERROR</span>
......@@ -231,14 +224,21 @@
<span class="n">MANDATORY_CONTINUATION</span> <span class="o">=</span> <span class="mi">1001</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">code</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">ERROR</span><span class="p">,</span> <span class="n">pos</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span>
<span class="n">orig_pos</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">orig_pos</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span>
<span class="n">node</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="s1">&#39;Node&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
<span class="k">assert</span> <span class="n">code</span> <span class="o">&gt;=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">code</span> <span class="o">=</span> <span class="n">code</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pos</span> <span class="o">=</span> <span class="n">add_pos</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="n">pos</span>
<span class="bp">self</span><span class="o">.</span><span class="n">orig_pos</span> <span class="o">=</span> <span class="n">orig_pos</span>
<span class="bp">self</span><span class="o">.</span><span class="n">line</span> <span class="o">=</span> <span class="n">line</span>
<span class="bp">self</span><span class="o">.</span><span class="n">column</span> <span class="o">=</span> <span class="n">column</span>
<span class="k">if</span> <span class="n">node</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">_pos</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">==</span> <span class="n">node</span><span class="o">.</span><span class="n">_pos</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_pos</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># if node is not needed, if pos has been set</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span> <span class="o">=</span> <span class="n">node</span> <span class="c1"># redundant: consider removing, see RootNode.collect_errors</span>
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">prefix</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
......@@ -250,6 +250,14 @@
<span class="k">return</span> <span class="s1">&#39;Error(&quot;</span><span class="si">%s</span><span class="s1">&quot;, </span><span class="si">%s</span><span class="s1">, </span><span class="si">%i</span><span class="s1">, </span><span class="si">%i</span><span class="s1">, </span><span class="si">%i</span><span class="s1">, </span><span class="si">%i</span><span class="s1">)&#39;</span> \
<span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">,</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">pos</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">orig_pos</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">line</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">column</span><span class="p">)</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">pos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span><span class="o">.</span><span class="n">pos</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;pos value not ready yet&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span><span class="o">.</span><span class="n">pos</span> <span class="c1"># lazy evaluation of position</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_node_keep</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># forget node to allow GC to free memory</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">severity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Returns a string representation of the error level, e.g. &quot;warning&quot;.&quot;&quot;&quot;</span>
......@@ -319,7 +327,7 @@
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">lbreaks</span> <span class="ow">and</span> <span class="n">pos</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pos</span>
<span class="k">if</span> <span class="n">pos</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">add_pos</span> <span class="o">&gt;</span> <span class="n">lbreaks</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span> <span class="c1"># one character behind EOF is still an allowed position!</span>
<span class="k">if</span> <span class="n">pos</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">pos</span> <span class="o">&gt;</span> <span class="n">lbreaks</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span> <span class="c1"># one character behind EOF is still an allowed position!</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Position </span><span class="si">%i</span><span class="s1"> outside text of length </span><span class="si">%s</span><span class="s1"> !&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="n">lbreaks</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">bisect</span><span class="o">.</span><span