94 lines
4.3 KiB
HTML
94 lines
4.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<!-- This manual documents Guile version 3.0.10.
|
|
|
|
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
|
|
Inc.
|
|
|
|
Copyright (C) 2021 Maxime Devos
|
|
|
|
Copyright (C) 2024 Tomas Volf
|
|
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation; with no
|
|
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
|
|
copy of the license is included in the section entitled "GNU Free
|
|
Documentation License." -->
|
|
<title>PEG Parsing (Guile Reference Manual)</title>
|
|
|
|
<meta name="description" content="PEG Parsing (Guile Reference Manual)">
|
|
<meta name="keywords" content="PEG Parsing (Guile Reference Manual)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content=".texi2any-real">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
<link href="index.html" rel="start" title="Top">
|
|
<link href="Concept-Index.html" rel="index" title="Concept Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="API-Reference.html" rel="up" title="API Reference">
|
|
<link href="Read_002fLoad_002fEval_002fCompile.html" rel="next" title="Read/Load/Eval/Compile">
|
|
<link href="LALR_00281_0029-Parsing.html" rel="prev" title="LALR(1) Parsing">
|
|
<style type="text/css">
|
|
<!--
|
|
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
|
|
span:hover a.copiable-link {visibility: visible}
|
|
-->
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<div class="section-level-extent" id="PEG-Parsing">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Read_002fLoad_002fEval_002fCompile.html" accesskey="n" rel="next">Reading and Evaluating Scheme Code</a>, Previous: <a href="LALR_00281_0029-Parsing.html" accesskey="p" rel="prev">LALR(1) Parsing</a>, Up: <a href="API-Reference.html" accesskey="u" rel="up">API Reference</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<h3 class="section" id="PEG-Parsing-1"><span>6.15 PEG Parsing<a class="copiable-link" href="#PEG-Parsing-1"> ¶</a></span></h3>
|
|
|
|
<p>Parsing Expression Grammars (PEGs) are a way of specifying formal
|
|
languages for text processing. They can be used either for matching
|
|
(like regular expressions) or for building recursive descent parsers
|
|
(like lex/yacc). Guile uses a superset of PEG syntax that allows more
|
|
control over what information is preserved during parsing.
|
|
</p>
|
|
<p>Wikipedia has a clear and concise introduction to PEGs if you want to
|
|
familiarize yourself with the syntax:
|
|
<a class="url" href="http://en.wikipedia.org/wiki/Parsing_expression_grammar">http://en.wikipedia.org/wiki/Parsing_expression_grammar</a>.
|
|
</p>
|
|
<p>The <code class="code">(ice-9 peg)</code> module works by compiling PEGs down to lambda
|
|
expressions. These can either be stored in variables at compile-time by
|
|
the define macros (<code class="code">define-peg-pattern</code> and
|
|
<code class="code">define-peg-string-patterns</code>) or calculated explicitly at runtime
|
|
with the compile functions (<code class="code">compile-peg-pattern</code> and
|
|
<code class="code">peg-string-compile</code>).
|
|
</p>
|
|
<p>They can then be used for either parsing (<code class="code">match-pattern</code>) or searching
|
|
(<code class="code">search-for-pattern</code>). For convenience, <code class="code">search-for-pattern</code>
|
|
also takes pattern literals in case you want to inline a simple search
|
|
(people often use regular expressions this way).
|
|
</p>
|
|
<p>The rest of this documentation consists of a syntax reference, an API
|
|
reference, and a tutorial.
|
|
</p>
|
|
|
|
<ul class="mini-toc">
|
|
<li><a href="PEG-Syntax-Reference.html" accesskey="1">PEG Syntax Reference</a></li>
|
|
<li><a href="PEG-API-Reference.html" accesskey="2">PEG API Reference</a></li>
|
|
<li><a href="PEG-Tutorial.html" accesskey="3">PEG Tutorial</a></li>
|
|
<li><a href="PEG-Internals.html" accesskey="4">PEG Internals</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|