corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [2/2] incubator-corinthia git commit: no experiments in a release
Date Wed, 05 Aug 2015 20:43:26 GMT
no experiments in a release


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/f937dc73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/f937dc73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/f937dc73

Branch: refs/heads/Release_0.1
Commit: f937dc73b24a65cc21f0c2130b3f4d4543ad92c9
Parents: 39e9a32
Author: jani <jani@apache.org>
Authored: Wed Aug 5 22:43:07 2015 +0200
Committer: jani <jani@apache.org>
Committed: Wed Aug 5 22:43:07 2015 +0200

----------------------------------------------------------------------
 experiments/flat/README.txt         |  25 --
 experiments/flat/grammars/flat.flat |  46 ---
 experiments/flat/src/BuildGrammar.c | 498 -------------------------------
 experiments/flat/src/BuildGrammar.h |  23 --
 experiments/flat/src/Builtin.c      | 241 ---------------
 experiments/flat/src/Builtin.h      |  73 -----
 experiments/flat/src/CMakeLists.txt |  59 ----
 experiments/flat/src/Common.h       |  26 --
 experiments/flat/src/Expression.c   | 496 ------------------------------
 experiments/flat/src/Expression.h   | 155 ----------
 experiments/flat/src/Grammar.c      | 133 ---------
 experiments/flat/src/Grammar.h      |  30 --
 experiments/flat/src/Parser.c       | 237 ---------------
 experiments/flat/src/Parser.h       |  23 --
 experiments/flat/src/Term.c         | 153 ----------
 experiments/flat/src/Term.h         |  50 ----
 experiments/flat/src/Util.c         | 123 --------
 experiments/flat/src/Util.h         |  25 --
 experiments/flat/src/flat.c         | 117 --------
 19 files changed, 2533 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/README.txt
----------------------------------------------------------------------
diff --git a/experiments/flat/README.txt b/experiments/flat/README.txt
deleted file mode 100644
index 436041a..0000000
--- a/experiments/flat/README.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-Flat (Formal LAanguage Transformation) is an experimental programming language
-for parsing, transforming, and pretty-printing any data format that can be
-expressed as a Parsing Expression Grammar (PEG) [1].
-
-Its purpose is to provide an easy way of dealing with file formats like
-Markdown, LaTeX, and org-mode which use a custom grammar, rather than a
-standardized meta-format like XML or JSON.
-
-Initially, the intention is to simply provide a parser interpreter (similar to a
-parser generator of the bison/flex variety) such that we can get an abstract
-syntax tree from a file, from which further processing can be done. The plan is
-to later extend it to include a domain-specific language for expressing
-transformations between different grammars, similar to Stratego/XT. [2]
-
-To understand PEGs, read the following papers:
-
-"Parsing Expression Grammars: A Recognition-Based Syntactic Foundation". Bryan
-Ford, POPL, January 2004. http://bford.info/pub/lang/peg.pdf
-
-"Packrat Parsing: Simple, Powerful, Lazy, Linear Time". Bryan Ford. ICFP,
-October 2002. http://bford.info/pub/lang/packrat-icfp02.pdf
-
-[1] http://bford.info/packrat
-
-[2] http://strategoxt.org

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/grammars/flat.flat
----------------------------------------------------------------------
diff --git a/experiments/flat/grammars/flat.flat b/experiments/flat/grammars/flat.flat
deleted file mode 100644
index bf6e794..0000000
--- a/experiments/flat/grammars/flat.flat
+++ /dev/null
@@ -1,46 +0,0 @@
-Grammar    : Spacing Definition+ EndOfFile;
-Definition : Identifier COLON Expression SEMI;
-Expression : Sequence (BAR Sequence)*;
-Sequence   : Prefix*;
-Prefix     : (AND | NOT)? Suffix;
-Suffix     : Primary (QUESTION | STAR | PLUS)?;
-Primary    : Identifier !COLON
-           | DOLLAR OPEN Expression CLOSE
-           | OPEN Expression CLOSE
-           | Literal
-           | Class
-           | DOT;
-Identifier : $(IdentStart IdentCont*) Spacing;
-IdentStart : [a-zA-Z_];
-IdentCont  : IdentStart
-           | [0-9];
-Literal    : ['] (!['] Char)* ['] Spacing
-           | ["] (!["] Char)* ["] Spacing;
-Class      : "[" (!"]" Range)* "]" Spacing;
-Range      : Char "-" Char
-           | Char;
-Char       : "\\" [nrt'"\[\]\\]
-           | "\\" [0-2] [0-7] [0-7]
-           | "\\" [0-7] [0-7]?
-           | !"\\" .;
-COLON      : ":" Spacing;
-SEMI       : ";" Spacing;
-BAR        : "|" Spacing;
-AND        : "&" Spacing;
-NOT        : "!" Spacing;
-QUESTION   : "?" Spacing;
-STAR       : "*" Spacing;
-PLUS       : "+" Spacing;
-OPEN       : "(" Spacing;
-CLOSE      : ")" Spacing;
-DOT        : "." Spacing;
-DOLLAR     : "$" Spacing;
-Spacing    : $((Space | Comment)*);
-Comment    : "#" (!EndOfLine .)* EndOfLine;
-Space      : " "
-           | "\t"
-           | EndOfLine;
-EndOfLine  : "\r\n"
-           | "\n"
-           | "\r";
-EndOfFile  : !.;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/BuildGrammar.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/BuildGrammar.c b/experiments/flat/src/BuildGrammar.c
deleted file mode 100644
index 7425878..0000000
--- a/experiments/flat/src/BuildGrammar.c
+++ /dev/null
@@ -1,498 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "BuildGrammar.h"
-#include "Util.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#define MAX_CHILDREN 64
-
-typedef struct Builder Builder;
-
-struct Builder {
-    Grammar *gram;
-    const char *input;
-    int len;
-};
-
-static Expression *buildExpression(Builder *builder, Term *term);
-
-static char *unescapeLiteral(const char *escaped)
-{
-    size_t escapedLen = strlen(escaped);
-    size_t escapedPos = 0;
-    size_t unescapedLen = 0;
-    char *unescaped = (char *)malloc(escapedLen+1);
-
-    while (escapedPos < escapedLen) {
-        char c = escaped[escapedPos++];
-        if ((c == '\\') && (escapedPos < escapedLen)) {
-            c = escaped[escapedPos++];
-            switch (c) {
-                case 'n':
-                    unescaped[unescapedLen++] = '\n';
-                    break;
-                case 'r':
-                    unescaped[unescapedLen++] = '\r';
-                    break;
-                case 't':
-                    unescaped[unescapedLen++] = '\t';
-                    break;
-                default:
-                    unescaped[unescapedLen++] = c;
-                    break;
-            }
-        }
-        else {
-            unescaped[unescapedLen++] = c;
-        }
-    }
-
-    unescaped[unescapedLen] = '\0';
-    return unescaped;
-}
-
-// Sanity checking functions
-//
-// These are just used to verify that a Term we're about to use is of the expected type.
-// Since the format of the parse tree is likely to change in these early stages of development,
-// this will catch cases where the code in this file has not been adapted to those changes
-//
-// The large number of assert statements in this file, most of which use these functions, will
-// likely only be necessary in the short term. Ideally we should be able to get to a point where
-// one can safely write code that consumes a parse tree without having so many sanity checks.
-
-static int isTerm(Term *term, ExprKind kind, int count)
-{
-    return ((TermKind(term) == kind) && (TermCount(term) == count));
-}
-
-static int isSequence(Term *term, int count)
-{
-    return isTerm(term,SequenceExpr,count);
-}
-
-static int isIdent(Term *term, const char *name)
-{
-    return (isTerm(term,IdentExpr,1) && !strcmp(name,ExprIdentValue(TermType(term))));
-}
-
-// Extract a substring of the input based on a specific term, or one or more children of a term.
-//
-// Each Term object has a start and end field, which specify which portion of the input string
-// the term covers (that is, the portion of the input consumed durin parsing of that term). In
-// some cases we want all the text matched by a term, and in others we only want the text matched
-// by specific children. An example of the latter is a "pseudo-terminal" like Identifier where
-// we want all characters except the trailing whitespace.
-
-static char *termString(Builder *builder, Term *term)
-{
-    assert(term->start >= 0);
-    assert(term->end <= builder->len);
-    int len = term->end - term->start;
-    char *str = malloc(len+1);
-    memcpy(str,&builder->input[term->start],len);
-    str[len] = '\0';
-    return str;
-}
-
-static char *identifierString(Builder *builder, Term *term)
-{
-    assert(isIdent(term,"Identifier"));
-    Term *body = TermChildAt(term,0);
-    assert(isSequence(body,2));
-    Term *content = TermChildAt(body,0);
-    Term *spacing = TermChildAt(body,1);
-    assert(TermKind(content) == StringExpr);
-    assert(isIdent(spacing,"Spacing"));
-    return termString(builder,content);
-}
-
-// For Terms of type ChoiceExpr, determine which of the choices the corresponding term is
-
-static int choiceIndex(Term *body)
-{
-    assert(TermKind(body) == ChoiceExpr);
-    assert(TermCount(body) == 1);
-    Term *choice = TermChildAt(body,0);
-    int match = -1;
-    int choiceCount = ExprChoiceCount(TermType(body));
-    for (int i = 0; i < choiceCount; i++) {
-        if (TermType(choice) == ExpressionChildAt(TermType(body),i))
-            match = i;
-    }
-    return match;
-}
-
-// Expression building functions (build*)
-//
-// There is one of these for each type of expression that can be present in the grammar. The
-// supplied Term object is, in all cases, of an IdentExpr type, whose single child is the body
-// of the corresponding grammar rule.
-//
-// For example, buildPrimary is called with an ExpressionType of IdentExpr "Primary", and the
-// body is a ChoiceExpr which can contain one of five possible child types, as given in the
-// PEG grammar.
-//
-// To see the exact expression tree of a given rule, look at its definition in Builtin.c
-
-static Expression *buildIdentifier(Builder *builder, Term *term)
-{
-    char *str = identifierString(builder,term);
-    Expression *result = ExpressionNewIdent(str);
-    free(str);
-    return result;
-}
-
-static Expression *buildLiteral(Builder *builder, Term *term)
-{
-    // The Literal rule in the built-in PEG grammar contains two choices - one for single quotes
-    // and the other for double quotes - which otherwise have the same structure. There are four
-    // children, where child 0 and child 2 represent the quotes themselves, child 1 represents the
-    // escaped representation of a string, and child 3 is any trailing whitespace.
-    //
-    // All we're interested in is the unescaped string, so we get child 2 and convert any escape
-    // sequences (e.g. \" or \n) to the characters they represent, and return a new literal
-    // expression with the unescaped string as its value.
-
-    assert(isIdent(term,"Literal"));
-    Term *body = TermChildAt(term,0);
-    assert(TermKind(body) == ChoiceExpr);
-    int index = choiceIndex(body);
-    assert((index == 0) || (index == 1));
-    Term *choice = TermChildAt(body,0);
-    assert(isSequence(choice,4));
-    Term *content = TermChildAt(choice,1);
-    char *escaped = termString(builder,content);
-    char *unescaped = unescapeLiteral(escaped);
-    Expression *result = ExpressionNewLit(unescaped);
-    free(escaped);
-    free(unescaped);
-    return result;
-}
-
-static int decodeRangeChar(Builder *builder, Term *charTerm)
-{
-    // FIXME: Handle non-ASCII chars encoded as UTF-8, as well as numeric escape sequences
-    // We don't need to allocate a string for unescaped here, we should just do it directly
-
-    assert(isIdent(charTerm,"Char"));
-    char *escaped = termString(builder,charTerm);
-    char *unescaped = unescapeLiteral(escaped);
-    int result;
-    if (strlen(unescaped) == 0)
-        result = '?';
-    else if (unescaped[0] < 0) // Start of UTF-8 multibyte sequence
-        result = '?';
-    else
-        result = unescaped[0];
-    free(escaped);
-    free(unescaped);
-    return result;
-}
-
-static Expression *buildRange(Builder *builder, Term *term)
-{
-    // A range expression, one or more of which appear inside a [...] character class expression,
-    // matches a character in a range between a start and end value. We use a single expression
-    // type to represent both exact matches (where the minimum and maximum are the same), and
-    // "true" ranges (which match two or more possible characters).
-    //
-    // Note that the representation we use for Range expressions is a (start,end) pair, where a
-    // character match must satisfy the condition start <= c < end (that is, the range includes the
-    // start, but does *not* include the end). This representation is for the convenience of other
-    // code that works with ranges. The ExpressionNewRange function however takes the minimum and
-    // maximum values - that is, a matching character c must satisfy min <= c <= max.
-
-    assert(isIdent(term,"Range"));
-    Term *body = TermChildAt(term,0);
-    int index = choiceIndex(body);
-    Term *choice = TermChildAt(body,0);
-    assert((index == 0) || (index == 1));
-    if (index == 0) {
-        assert(isSequence(choice,3));
-        Term *minChar = TermChildAt(choice,0);
-        Term *maxChar = TermChildAt(choice,2);
-        assert(isIdent(minChar,"Char"));
-        assert(isIdent(maxChar,"Char"));
-        int min = decodeRangeChar(builder,minChar);
-        int max = decodeRangeChar(builder,maxChar);
-        return ExpressionNewRange(min,max);
-    }
-    else {
-        assert(isIdent(choice,"Char"));
-        int value = decodeRangeChar(builder,choice);
-        return ExpressionNewRange(value,value);
-    }
-}
-
-static Expression *buildClass(Builder *builder, Term *term)
-{
-    // A character class expression is the same as a choice expression, except that it is only
-    // supposed to contain range expressions.
-
-    assert(isIdent(term,"Class"));
-    Term *body = TermChildAt(term,0);
-    assert(isSequence(body,4));
-    Term *star = TermChildAt(body,1);
-    assert(TermKind(star) == StarExpr);
-
-    Expression *children[MAX_CHILDREN];
-    int count = 0;
-    for (TermList *item = TermChildren(star); (item != NULL) && (count < MAX_CHILDREN); item = item->next) {
-        assert(isSequence(item->term,2));
-        Term *rangeTerm = TermChildAt(item->term,1);
-        Expression *rangeExpr = buildRange(builder,rangeTerm);
-        children[count++] = rangeExpr;
-    }
-
-    return ExpressionNewClass(count,children);
-}
-
-static Expression *buildDot(Builder *builder, Term *term)
-{
-    assert(isIdent(term,"DOT"));
-    return ExpressionNewDot();
-}
-
-static Expression *buildPrimary(Builder *builder, Term *term)
-{
-    // A primary expression can be one of five possibilities: An identifier (reference to another
-    // rule in the grammar), a parenthesised expresion, a literal, a character class, or a dot
-    // (which matches any character).
-    //
-    // The type of the term is an Expression with kind == ChoiceExpr, and the term has exactly
-    // one child. We use choiceIndex to determine which of the five possible expression types
-    // the choice matches, and then call through to the relevant function to build the appropriate
-    // type of Expression object.
-
-    assert(isIdent(term,"Primary"));
-    Term *body = TermChildAt(term,0);
-    assert(TermKind(body) == ChoiceExpr);
-    assert(TermCount(body) == 1);
-    Term *choice = TermChildAt(body,0);
-
-    switch (choiceIndex(body)) {
-        case 0: {
-            assert(isSequence(choice,2));
-            Term *identifier = TermChildAt(choice,0);
-            return buildIdentifier(builder,identifier);
-        }
-        case 1: {
-            assert(isSequence(choice,4));
-            Term *expression = TermChildAt(choice,2);
-            Expression *result = buildExpression(builder,expression);
-            return ExpressionNewString(result);
-        }
-        case 2: {
-            assert(isSequence(choice,3));
-            Term *expression = TermChildAt(choice,1);
-            return buildExpression(builder,expression);
-        }
-        case 3:
-            return buildLiteral(builder,choice);
-        case 4:
-            return buildClass(builder,choice);
-        case 5:
-            return buildDot(builder,choice);
-        default:
-            assert(!"Invalid choice for Primary");
-            return NULL;
-    }
-}
-
-static Expression *buildSuffix(Builder *builder, Term *term)
-{
-    // A suffix expression has two children. The second is optional, and is one of either QUESTION,
-    // STAR, or PLUS - which indicate that the first child may occur zero or one times, zero or more
-    // times, or one or more times. The first child is always present, and represents a primary
-    // expression with no prefix or suffix.
-    //
-    // If a QUESTION, STAR, or PLUS suffix is given, we wrap the constructed primary expression
-    // inside another Expression object of type OptExpr, StarExpr, or PlusExpr. Otherwise, we just
-    // return the primary expression directly.
-
-    assert(isIdent(term,"Suffix"));
-    Term *body = TermChildAt(term,0);
-    assert(isSequence(body,2));
-    Term *primary = TermChildAt(body,0);
-    Term *suffix = TermChildAt(body,1);
-    assert(isIdent(primary,"Primary"));
-    assert(TermKind(suffix) == OptExpr);
-
-    Expression *primaryExpr = buildPrimary(builder,primary);
-
-    assert((TermCount(suffix) == 0) || (TermCount(suffix) == 1));
-    if (TermCount(suffix) == 1) {
-        Term *suffixChild = TermChildAt(suffix,0);
-        int index = choiceIndex(suffixChild);
-        Term *choice = TermChildAt(suffixChild,0);
-        switch (index) {
-            case 0:
-                assert(isIdent(choice,"QUESTION"));
-                return ExpressionNewOpt(primaryExpr);
-            case 1:
-                assert(isIdent(choice,"STAR"));
-                return ExpressionNewStar(primaryExpr);
-            case 2:
-                assert(isIdent(choice,"PLUS"));
-                return ExpressionNewPlus(primaryExpr);
-            default:
-                assert(!"Invalid choice for Suffix");
-                break;
-        }
-    }
-
-    return primaryExpr;
-}
-
-static Expression *buildPrefix(Builder *builder, Term *term)
-{
-    // A prefix expression has two children. The first is optional, and is one of either AND or
-    // NOT - which indicate a positive or negative lookahead assertion. The second is not optional,
-    // and represents a primary expression with an optional suffix.
-    //
-    // If an AND or NOT prefx is given, we wrap the constructed primary expression inside another
-    // Expression object of type AndExpr or NotExpr. Otherwise, we just return the primary
-    // expression directly.
-
-    assert(isIdent(term,"Prefix"));
-    Term *body = TermChildAt(term,0);
-    assert(isSequence(body,2));
-    Term *prefix = TermChildAt(body,0);
-    Term *suffix = TermChildAt(body,1);
-    assert(TermKind(prefix) == OptExpr);
-    assert(isIdent(suffix,"Suffix"));
-
-    Expression *suffixExpr = buildSuffix(builder,suffix);
-
-    assert((TermCount(prefix) == 0) || (TermCount(prefix) == 1));
-    if (TermCount(prefix) == 1) {
-        Term *prefixChild = TermChildAt(prefix,0);
-        int index = choiceIndex(prefixChild);
-        Term *choice = TermChildAt(prefixChild,0);
-        switch (index) {
-            case 0:
-                assert(isIdent(choice,"AND"));
-                return ExpressionNewAnd(suffixExpr);
-            case 1:
-                assert(isIdent(choice,"NOT"));
-                return ExpressionNewNot(suffixExpr);
-            default:
-                assert(!"Invalid choice for Prefix");
-                break;
-        }
-    }
-
-    return suffixExpr;
-}
-
-static Expression *buildSequence(Builder *builder, Term *term)
-{
-    // An Sequence consists of one or more expressions, each of which has an optional prefix
-    // and suffix
-    assert(isIdent(term,"Sequence"));
-    Term *body = TermChildAt(term,0);
-    assert(TermKind(body) == StarExpr);
-
-    Expression *children[MAX_CHILDREN];
-    int count = 0;
-    for (TermList *item = TermChildren(body); (item != NULL) && (count < MAX_CHILDREN); item = item->next) {
-        children[count] = buildPrefix(builder,item->term);
-        count++;
-    }
-    if (count == 1)
-        return children[0];
-    else
-        return ExpressionNewSequence(count,children);
-}
-
-static Expression *buildExpression(Builder *builder, Term *term)
-{
-    // An Expression consists of one or more choices
-    assert(isIdent(term,"Expression"));
-    Term *body = TermChildAt(term,0);
-    assert(isSequence(body,2));
-
-    Term *child0 = TermChildAt(body,0);
-    Term *child1 = TermChildAt(body,1);
-
-    assert(isIdent(child0,"Sequence"));
-    assert(TermKind(child1) == StarExpr);
-
-    Expression *initial = buildSequence(builder,child0);
-    if (TermCount(child1) == 0)
-        return initial;
-
-    Expression *children[MAX_CHILDREN];
-    children[0] = initial;
-    int count = 1;
-    for (TermList *item = TermChildren(child1); (item != NULL) && (count < MAX_CHILDREN); item = item->next) {
-        assert(isSequence(item->term,2));
-        children[count] = buildSequence(builder,TermChildAt(item->term,1));
-        count++;
-    }
-    return ExpressionNewChoice(count,children);
-}
-
-static void buildGrammar(Builder *builder, Term *term)
-{
-    assert(isSequence(term,3));
-    Term *plus = TermChildAt(term,1);
-    assert(TermKind(plus) == PlusExpr);
-
-    for (TermList *plusItem = plus->children; plusItem != NULL; plusItem = plusItem->next) {
-        Term *defIdent = plusItem->term;
-        assert(isIdent(defIdent,"Definition"));
-        Term *defSeq = TermChildAt(defIdent,0);
-        assert(isSequence(defSeq,4));
-        Term *identTerm = TermChildAt(defSeq,0);
-        Term *exprTerm = TermChildAt(defSeq,2);
-        assert(isIdent(identTerm,"Identifier"));
-        assert(isIdent(exprTerm,"Expression"));
-
-        char *ruleName = identifierString(builder,identTerm);
-        Expression *ruleExpr = buildExpression(builder,exprTerm);
-        GrammarDefine(builder->gram,ruleName,ruleExpr);
-        free(ruleName);
-    }
-}
-
-// This function creates a new Grammar object from the result of parsing a file usin the built-in
-// PEG grammar. The resulting Grammar object can then be used to parse other files which are written
-// in another language that is accepted by that grammar. The Term objects are constructed by the
-// parse function defined in Parser.c.
-
-Grammar *grammarFromTerm(Term *term, const char *input)
-{
-    Grammar *gram = GrammarNew();
-
-    Builder *builder = (Builder *)calloc(1,sizeof(Builder));
-    builder->gram = gram;
-    builder->input = input;
-    builder->len = strlen(input);
-
-    buildGrammar(builder,term);
-
-    free(builder);
-
-    return gram;
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/BuildGrammar.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/BuildGrammar.h b/experiments/flat/src/BuildGrammar.h
deleted file mode 100644
index dcf4759..0000000
--- a/experiments/flat/src/BuildGrammar.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include "Grammar.h"
-#include "Term.h"
-
-Grammar *grammarFromTerm(Term *term, const char *input);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Builtin.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Builtin.c b/experiments/flat/src/Builtin.c
deleted file mode 100644
index ce060cb..0000000
--- a/experiments/flat/src/Builtin.c
+++ /dev/null
@@ -1,241 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Builtin.h"
-#include <stdarg.h>
-#include <stdlib.h>
-
-#define ref(name)       ExpressionNewIdent(name)
-#define choice(...)     makeExpression(ExpressionNewChoice,__VA_ARGS__,NULL)
-#define seq(...)        makeExpression(ExpressionNewSequence,__VA_ARGS__,NULL)
-#define and(child)      ExpressionNewAnd(child)
-#define not(child)      ExpressionNewNot(child)
-#define opt(child)      ExpressionNewOpt(child)
-#define star(child)     ExpressionNewStar(child)
-#define plus(child)     ExpressionNewPlus(child)
-#define lit(value)      ExpressionNewLit(value)
-#define cls(...)        makeExpression(ExpressionNewClass,__VA_ARGS__,NULL)
-#define dot()           ExpressionNewDot()
-#define string(child)   ExpressionNewString(child)
-#define range(lo,hi)    ExpressionNewRange(lo,hi)
-
-static Expression *makeExpression(Expression *(*fun)(int,Expression **), ...)
-{
-    Expression *children[20];
-    int count = 0;
-    va_list ap;
-    va_start(ap,fun);
-    Expression *expr;
-    while ((count < 20) && ((expr = va_arg(ap,Expression *)) != NULL))
-        children[count++] = expr;
-    va_end(ap);
-    return fun(count,children);
-}
-
-Grammar *GrammarNewBuiltin(void)
-{
-    Grammar *gram = GrammarNew();
-
-    // Grammar : Spacing Definition+ EndOfFile
-    GrammarDefine(gram,"Grammar",
-                  seq(ref("Spacing"),
-                      plus(ref("Definition")),
-                      ref("EndOfFile")));
-
-    // Definition : Identifier COLON Expression SEMI
-    GrammarDefine(gram,"Definition",
-                  seq(ref("Identifier"),
-                      ref("COLON"),
-                      ref("Expression"),
-                      ref("SEMI")));
-
-    // Expression : Sequence (BAR Sequence)*
-    GrammarDefine(gram,"Expression",
-                  seq(ref("Sequence"),
-                      star(seq(ref("BAR"),ref("Sequence")))));
-
-    // Sequence : Prefix*
-    GrammarDefine(gram,"Sequence",
-                  star(ref("Prefix")));
-
-    // Prefix : (AND | NOT)? Suffix
-    GrammarDefine(gram,"Prefix",
-                  seq(opt(choice(ref("AND"),
-                                 ref("NOT"))),
-                      ref("Suffix")));
-
-    // Suffix : Primary (QUESTION | STAR | PLUS)?
-    GrammarDefine(gram,"Suffix",
-                  seq(ref("Primary"),
-                      opt(choice(ref("QUESTION"),
-                                 ref("STAR"),
-                                 ref("PLUS")))));
-
-    // Primary : Identifier !COLON
-    //         | DOLLAR OPEN Expression CLOSE
-    //         | OPEN Expression CLOSE
-    //         | Literal
-    //         | Class
-    //         | DOT
-    GrammarDefine(gram,"Primary",
-                  choice(seq(ref("Identifier"),not(ref("COLON"))),
-                         seq(ref("DOLLAR"),ref("OPEN"),ref("Expression"),ref("CLOSE")),
-                         seq(ref("OPEN"),ref("Expression"),ref("CLOSE")),
-                         ref("Literal"),
-                         ref("Class"),
-                         ref("DOT")));
-
-    // Identifier : $(IdentStart IdentCont*) Spacing
-    GrammarDefine(gram,"Identifier",
-                  seq(string(seq(ref("IdentStart"),
-                                 star(ref("IdentCont")))),
-                      ref("Spacing")));
-
-    // IdentStart : [a-zA-Z_]
-    GrammarDefine(gram,"IdentStart",
-                  cls(range('a','z'),
-                      range('A','Z'),
-                      range('_','_')));
-
-    // IdentCont : IdentStart
-    //           | [0-9]
-    GrammarDefine(gram,"IdentCont",
-                  choice(ref("IdentStart"),
-                         cls(range('0','9'))));
-
-    // Literal : ['] (!['] Char)* ['] Spacing
-    //         | ["] (!["] Char)* ["] Spacing
-    GrammarDefine(gram,"Literal",
-                  choice(seq(cls(range('\'','\'')),
-                             star(seq(not(cls(range('\'','\''))),
-                                      ref("Char"))),
-                             cls(range('\'','\'')),
-                             ref("Spacing")),
-                         seq(cls(range('"','"')),
-                             star(seq(not(cls(range('"','"'))),
-                                      ref("Char"))),
-                             cls(range('"','"')),
-                             ref("Spacing"))));
-
-    // Class : "[" (!"]" Range)* "]" Spacing
-    GrammarDefine(gram,"Class",
-                  seq(lit("["),
-                      star(seq(not(lit("]")),
-                               ref("Range"))),
-                      lit("]"),
-                      ref("Spacing")));
-
-    // Range : Char "-" Char
-    //       | Char
-    GrammarDefine(gram,"Range",
-                  choice(seq(ref("Char"),
-                             lit("-"),
-                             ref("Char")),
-                         ref("Char")));
-
-    // Char : "\\" [nrt'"\[\]\\]
-    //      | "\\" [0-2] [0-7] [0-7]
-    //      | "\\" [0-7] [0-7]?
-    //      | !"\\" .
-    GrammarDefine(gram,"Char",
-                  choice(seq(lit("\\"),
-                             cls(range('n','n'),
-                                 range('r','r'),
-                                 range('t','t'),
-                                 range('\'','\''),
-                                 range('"','"'),
-                                 range('[','['),
-                                 range(']',']'),
-                                 range('\\','\\'))),
-                         seq(lit("\\"),
-                             cls(range('0','2')),
-                             cls(range('0','7')),
-                             cls(range('0','7'))),
-                         seq(lit("\\"),
-                             cls(range('0','7')),
-                             opt(cls(range('0','7')))),
-                         seq(not(lit("\\")),dot())));
-
-    // COLON : ":" Spacing
-    GrammarDefine(gram,"COLON",seq(lit(":"),ref("Spacing")));
-
-    // SEMI : ";" Spacing
-    GrammarDefine(gram,"SEMI",seq(lit(";"),ref("Spacing")));
-
-    // BAR : "|" Spacing
-    GrammarDefine(gram,"BAR",seq(lit("|"),ref("Spacing")));
-
-    // AND : "&" Spacing
-    GrammarDefine(gram,"AND",seq(lit("&"),ref("Spacing")));
-
-    // NOT : "!" Spacing
-    GrammarDefine(gram,"NOT",seq(lit("!"),ref("Spacing")));
-
-    // QUESTION : "?" Spacing
-    GrammarDefine(gram,"QUESTION",seq(lit("?"),ref("Spacing")));
-
-    // STAR : "*" Spacing
-    GrammarDefine(gram,"STAR",seq(lit("*"),ref("Spacing")));
-
-    // PLUS : "+" Spacing
-    GrammarDefine(gram,"PLUS",seq(lit("+"),ref("Spacing")));
-
-    // OPEN : "(" Spacing
-    GrammarDefine(gram,"OPEN",seq(lit("("),ref("Spacing")));
-
-    // CLOSE : ")" Spacing
-    GrammarDefine(gram,"CLOSE",seq(lit(")"),ref("Spacing")));
-
-    // DOT : "." Spacing
-    GrammarDefine(gram,"DOT",seq(lit("."),ref("Spacing")));
-
-    // DOLLAR : "$" Spacing
-    GrammarDefine(gram,"DOLLAR",seq(lit("$"),ref("Spacing")));
-
-    // Spacing : $((Space | Comment)*)
-    GrammarDefine(gram,"Spacing",string(star(choice(ref("Space"),ref("Comment")))));
-
-    // Comment : "#" (!EndOfLine .)* EndOfLine;
-    GrammarDefine(gram,"Comment",
-                  seq(lit("#"),
-                      star(seq(not(ref("EndOfLine")),
-                               dot())),
-                      ref("EndOfLine")));
-
-    // Space : " "
-    //       | "\t"
-    //       | EndOfLine
-    GrammarDefine(gram,"Space",
-                  choice(lit(" "),
-                         lit("\t"),
-                         ref("EndOfLine")));
-    // EndOfLine : "\r\n"
-    //           | "\n"
-    //           | "\r"
-    GrammarDefine(gram,"EndOfLine",
-                  choice(lit("\r\n"),
-                         lit("\n"),
-                         lit("\r")));
-
-    // EndOfFile : !.
-    GrammarDefine(gram,"EndOfFile",not(dot()));
-
-    GrammarResolve(gram);
-
-    return gram;
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Builtin.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Builtin.h b/experiments/flat/src/Builtin.h
deleted file mode 100644
index 76d3f38..0000000
--- a/experiments/flat/src/Builtin.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include "Grammar.h"
-
-/**
- * The GrammarNewBuiltin() function creates the grammar shown below, which is based on the one from
- * Ford's original PEG paper.
- *
- *     Grammar    : Spacing Definition+ EndOfFile;
- *     Definition : Identifier COLON Expression SEMI;
- *     Expression : Sequence (BAR Sequence)*;
- *     Sequence   : Prefix*;
- *     Prefix     : (AND | NOT)? Suffix;
- *     Suffix     : Primary (QUESTION | STAR | PLUS)?;
- *     Primary    : Identifier !COLON
- *                | DOLLAR OPEN Expression CLOSE
- *                | OPEN Expression CLOSE
- *                | Literal
- *                | Class
- *                | DOT;
- *     Identifier : $(IdentStart IdentCont*) Spacing;
- *     IdentStart : [a-zA-Z_];
- *     IdentCont  : IdentStart
- *                | [0-9];
- *     Literal    : ['] (!['] Char)* ['] Spacing
- *                | ["] (!["] Char)* ["] Spacing;
- *     Class      : "[" (!"]" Range)* "]" Spacing;
- *     Range      : Char "-" Char
- *                | Char;
- *     Char       : "\\" [nrt'"\[\]\\]
- *                | "\\" [0-2] [0-7] [0-7]
- *                | "\\" [0-7] [0-7]?
- *                | !"\\" .;
- *     COLON      : ":" Spacing;
- *     SEMI       : ";" Spacing;
- *     BAR        : "|" Spacing;
- *     AND        : "&" Spacing;
- *     NOT        : "!" Spacing;
- *     QUESTION   : "?" Spacing;
- *     STAR       : "*" Spacing;
- *     PLUS       : "+" Spacing;
- *     OPEN       : "(" Spacing;
- *     CLOSE      : ")" Spacing;
- *     DOT        : "." Spacing;
- *     DOLLAR     : "$" Spacing;
- *     Spacing    : $((Space | Comment)*);
- *     Comment    : "#" (!EndOfLine .)* EndOfLine;
- *     Space      : " "
- *                | "\t"
- *                | EndOfLine;
- *     EndOfLine  : "\r\n"
- *                | "\n"
- *                | "\r";
- *     EndOfFile  : !.;
- */
-Grammar *GrammarNewBuiltin(void);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/experiments/flat/src/CMakeLists.txt b/experiments/flat/src/CMakeLists.txt
deleted file mode 100644
index 12ede19..0000000
--- a/experiments/flat/src/CMakeLists.txt
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-
-###
-## global definitions
-###
-set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-
-
-###
-## group source objects
-###
-set(SOURCES
-    BuildGrammar.c
-    BuildGrammar.h
-    Builtin.c
-    Builtin.h
-    Common.h
-    Expression.c
-    Expression.h
-    Grammar.c
-    Grammar.h
-    Parser.c
-    Parser.h
-    Term.c
-    Term.h
-    Util.c
-    Util.h
-    flat.c)
-
-###
-# Common include for all platform files
-###
-include_directories()
-include_directories(SYSTEM ${INCLUDE_DIRS})
-include_directories(.)
-link_directories(${LIB_DIRS})
-
-
-
-###
-# executable (release artifact)
-###
-add_executable(flat ${SOURCES})
-#target_link_libraries(flat DocFormats ${LIBS})
-source_group(src FILES ${SOURCES})
-set_property(TARGET flat PROPERTY FOLDER experiments)

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Common.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Common.h b/experiments/flat/src/Common.h
deleted file mode 100644
index 90c8f91..0000000
--- a/experiments/flat/src/Common.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-// Ultimately we should use DFPlatform.h or a similarly-named shared header here. However currently
-// I want to keep the source tree for Flat separate from DocFormats so it can work as an independent
-// library, at least during the "experimental" phase of development.
-
-#ifdef _WINDOWS
-#define snprintf _snprintf
-#endif // _WINDOWS

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Expression.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Expression.c b/experiments/flat/src/Expression.c
deleted file mode 100644
index ad2fc2e..0000000
--- a/experiments/flat/src/Expression.c
+++ /dev/null
@@ -1,496 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Expression.h"
-#include "Util.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-struct Expression {
-    ExprKind kind;
-    int count;
-    char *value;
-    int start;
-    int end;
-    Expression *children[];
-};
-
-const char *ExprKindAsString(ExprKind kind)
-{
-    switch (kind) {
-        case ChoiceExpr:
-            return "Choice";
-        case SequenceExpr:
-            return "Sequence";
-        case AndExpr:
-            return "And";
-        case NotExpr:
-            return "Not";
-        case OptExpr:
-            return "Opt";
-        case StarExpr:
-            return "Star";
-        case PlusExpr:
-            return "Plus";
-        case IdentExpr:
-            return "Ident";
-        case LitExpr:
-            return "Lit";
-        case ClassExpr:
-            return "Class";
-        case DotExpr:
-            return "Dot";
-        case RangeExpr:
-            return "Range";
-        case StringExpr:
-            return "String";
-    }
-    return "?";
-}
-
-Expression *ExpressionNewChoice(int count, Expression **children)
-{
-    for (int i = 0; i < count; i++)
-        assert(children[i] != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+count*sizeof(Expression *));
-    expr->kind = ChoiceExpr;
-    expr->count = count;
-    memcpy(expr->children,children,count*sizeof(Expression *));
-    return expr;
-}
-
-Expression *ExpressionNewSequence(int count, Expression **children)
-{
-    for (int i = 0; i < count; i++)
-        assert(children[i] != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+count*sizeof(Expression *));
-    expr->kind = SequenceExpr;
-    expr->count = count;
-    memcpy(expr->children,children,count*sizeof(Expression *));
-    return expr;
-}
-
-Expression *ExpressionNewAnd(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = AndExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-Expression *ExpressionNewNot(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = NotExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-Expression *ExpressionNewOpt(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = OptExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-Expression *ExpressionNewStar(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = StarExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-Expression *ExpressionNewPlus(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = PlusExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-Expression *ExpressionNewIdent(const char *ident)
-{
-    assert(ident != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = IdentExpr;
-    expr->value = strdup(ident);
-    expr->count = 1;
-    expr->children[0] = NULL;
-    return expr;
-}
-
-Expression *ExpressionNewLit(const char *value)
-{
-    assert(value != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression));
-    expr->kind = LitExpr;
-    expr->value = strdup(value);
-    expr->count = 0;
-    return expr;
-}
-
-Expression *ExpressionNewClass(int count, Expression **children)
-{
-    for (int i = 0; i < count; i++) {
-        assert(children[i] != NULL);
-        assert(children[i]->kind == RangeExpr);
-    }
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+count*sizeof(Expression *));
-    expr->kind = ClassExpr;
-    expr->count = count;
-    memcpy(expr->children,children,count*sizeof(Expression *));
-    return expr;
-}
-
-Expression *ExpressionNewDot(void)
-{
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression));
-    expr->kind = DotExpr;
-    return expr;
-}
-
-Expression *ExpressionNewRange(int lo, int hi)
-{
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression));
-    expr->kind = RangeExpr;
-    expr->start = lo;
-    expr->end = hi+1;
-    return expr;
-}
-
-Expression *ExpressionNewString(Expression *child)
-{
-    assert(child != NULL);
-    Expression *expr = (Expression *)calloc(1,sizeof(Expression)+1*sizeof(Expression *));
-    expr->kind = StringExpr;
-    expr->count = 1;
-    expr->children[0] = child;
-    return expr;
-}
-
-void ExpressionFree(Expression *expr)
-{
-    if (expr == NULL)
-        return;
-    free(expr->value);
-    // Don't free children of IdentExpr, since these are expressions referenced by grammar
-    // rules, which will be freed separately. We can't use reference counting here as there
-    // will generally by cycles.
-    if (expr->kind != IdentExpr) {
-        for (int i = 0; i < expr->count; i++)
-            ExpressionFree(expr->children[i]);
-    }
-    free(expr);
-}
-
-static int ExprKindPrecedence(ExprKind kind)
-{
-    switch (kind) {
-        case ChoiceExpr:
-            return 1;
-        case SequenceExpr:
-            return 2;
-        case AndExpr:
-        case NotExpr:
-            return 3;
-        case OptExpr:
-        case StarExpr:
-        case PlusExpr:
-            return 4;
-        case IdentExpr:
-        case LitExpr:
-        case ClassExpr:
-        case DotExpr:
-            return 5;
-        case StringExpr:
-            return 6;
-        case RangeExpr:
-            return 7;
-    }
-    return 0;
-}
-
-void ExpressionPrint(Expression *expr, int highestPrecedence, const char *indent)
-{
-    int exprPrecedence = ExprKindPrecedence(expr->kind);
-    int brackets = (highestPrecedence > exprPrecedence); // e.g. a choice inside a sequence
-    if (highestPrecedence < exprPrecedence)
-        highestPrecedence = exprPrecedence;
-
-    if ((expr->kind == ClassExpr) || (expr->kind == RangeExpr))
-        brackets = 0;
-
-    if (brackets) {
-        printf("(");
-        highestPrecedence = 1;
-    }
-    switch (expr->kind) {
-        case ChoiceExpr:
-            for (int i = 0; i < ExprChoiceCount(expr); i++) {
-                if (i > 0) {
-                    if (indent != NULL)
-                        printf("\n%s| ",indent);
-                    else
-                        printf(" | ");
-                }
-                ExpressionPrint(ExprChoiceChildAt(expr,i),highestPrecedence,NULL);
-            }
-            break;
-        case SequenceExpr: {
-            for (int i = 0; i < ExprSequenceCount(expr); i++) {
-                if (i > 0) {
-                    printf(" ");
-                }
-                ExpressionPrint(ExprSequenceChildAt(expr,i),highestPrecedence,NULL);
-            }
-            break;
-        }
-        case AndExpr:
-            printf("&");
-            ExpressionPrint(ExprAndChild(expr),highestPrecedence,NULL);
-            break;
-        case NotExpr:
-            printf("!");
-            ExpressionPrint(ExprNotChild(expr),highestPrecedence,NULL);
-            break;
-        case OptExpr:
-            ExpressionPrint(ExprOptChild(expr),highestPrecedence,NULL);
-            printf("?");
-            break;
-        case StarExpr:
-            ExpressionPrint(ExprStarChild(expr),highestPrecedence,NULL);
-            printf("*");
-            break;
-        case PlusExpr:
-            ExpressionPrint(ExprPlusChild(expr),highestPrecedence,NULL);
-            printf("+");
-            break;
-        case IdentExpr:
-            printf("%s",ExprIdentValue(expr));
-            break;
-        case LitExpr:
-            printLiteral(ExprLitValue(expr));
-            break;
-        case ClassExpr:
-            printf("[");
-            for (int i = 0; i < ExprClassCount(expr); i++) {
-                ExpressionPrint(ExprClassChildAt(expr,i),highestPrecedence,NULL);
-            }
-            printf("]");
-            break;
-        case DotExpr:
-            printf(".");
-            break;
-        case RangeExpr: {
-            int start = ExprRangeStart(expr);
-            int end = ExprRangeEnd(expr);
-            if (start+1 == end) {
-                printEscapedRangeChar(start);
-            }
-            else {
-                printEscapedRangeChar(start);
-                printf("-");
-                printEscapedRangeChar(end-1);
-            }
-            break;
-        }
-        case StringExpr:
-            printf("$(");
-            highestPrecedence = 1; // because of brackets
-            ExpressionPrint(ExprStringChild(expr),highestPrecedence,NULL);
-            printf(")");
-            break;
-    }
-    if (brackets)
-        printf(")");
-}
-
-ExprKind ExpressionKind(Expression *expr)
-{
-    return expr->kind;
-}
-
-int ExpressionCount(Expression *expr)
-{
-    return expr->count;
-}
-
-Expression *ExpressionChildAt(Expression *expr, int index)
-{
-    if ((index < 0) || (index >= expr->count))
-        return NULL;
-    return expr->children[index];
-}
-
-// Choice
-
-int ExprChoiceCount(Expression *expr)
-{
-    assert(expr->kind == ChoiceExpr);
-    return expr->count;
-}
-
-Expression *ExprChoiceChildAt(Expression *expr, int index)
-{
-    assert(expr->kind == ChoiceExpr);
-    assert(index >= 0);
-    assert(index < expr->count);
-    return expr->children[index];
-}
-
-// Sequence
-
-int ExprSequenceCount(Expression *expr)
-{
-    assert(expr->kind == SequenceExpr);
-    return expr->count;
-}
-
-Expression *ExprSequenceChildAt(Expression *expr, int index)
-{
-    assert(expr->kind == SequenceExpr);
-    assert(index >= 0);
-    assert(index < expr->count);
-    return expr->children[index];
-}
-
-// And, Not, Opt, Star, Plus
-
-Expression *ExprAndChild(Expression *expr)
-{
-    assert(expr->kind == AndExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-Expression *ExprNotChild(Expression *expr)
-{
-    assert(expr->kind == NotExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-Expression *ExprOptChild(Expression *expr)
-{
-    assert(expr->kind == OptExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-Expression *ExprStarChild(Expression *expr)
-{
-    assert(expr->kind == StarExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-Expression *ExprPlusChild(Expression *expr)
-{
-    assert(expr->kind == PlusExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-// Ident, Lit
-
-const char *ExprIdentValue(Expression *expr)
-{
-    assert(expr->kind == IdentExpr);
-    return expr->value;
-}
-
-Expression *ExprIdentTarget(Expression *expr)
-{
-    assert(expr->kind == IdentExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}
-
-void ExprIdentSetTarget(Expression *expr, Expression *target)
-{
-    assert(expr->kind == IdentExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] == NULL);
-    expr->children[0] = target;
-}
-
-const char *ExprLitValue(Expression *expr)
-{
-    assert(expr->kind == LitExpr);
-    return expr->value;
-}
-
-// Class
-
-int ExprClassCount(Expression *expr)
-{
-    assert(expr->kind == ClassExpr);
-    return expr->count;
-}
-
-Expression *ExprClassChildAt(Expression *expr, int index)
-{
-    assert(expr->kind == ClassExpr);
-    assert(index >= 0);
-    assert(index < expr->count);
-    return expr->children[index];
-}
-
-// Range
-
-int ExprRangeStart(Expression *expr)
-{
-    assert(expr->kind == RangeExpr);
-    return expr->start;
-}
-
-int ExprRangeEnd(Expression *expr)
-{
-    assert(expr->kind == RangeExpr);
-    return expr->end;
-}
-
-// String
-
-Expression *ExprStringChild(Expression *expr)
-{
-    assert(expr->kind == StringExpr);
-    assert(expr->count == 1);
-    assert(expr->children[0] != NULL);
-    return expr->children[0];
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Expression.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Expression.h b/experiments/flat/src/Expression.h
deleted file mode 100644
index 1058be0..0000000
--- a/experiments/flat/src/Expression.h
+++ /dev/null
@@ -1,155 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-/**
- * A tree of Expression objects represents the abstract syntax tree that comprises part of a
- * PEG (Parsing Expression Grammar). Each grammar consists of one or more named rules, each
- * of which has an expression tree associated with it. The format of the grammars is described
- * in the following paper:
- *
- *     "Parsing Expression Grammars: A Recognition-Based Syntactic Foundation".
- *     Bryan Ford, POPL, January 2004. http://bford.info/pub/lang/peg.pdf
- *
- * An Expression can be used by a code generator to produce the code for a parser, or alternatively,
- * used directly to implement an interpreter to produce a parse tree based on the rules of the
- * grammar.
- *
- * The types are as follows:
- *
- * ChoiceExpr - matches exactly one of the child expressions against the input. Each expression
- * is tested in order, until a match is found, with the result being that of the child parse.
- * Evaluation succeeds if one of the children matched.
- *
- * SequenceExpr - matches each of the child expressions, in order, following consecutively in the
- * input. Evaluation succeeds if all children matched.
- *
- * AndExpr - Positive lookahead assertion. The single child expression is tested against the input,
- * and evaluation succeeds if there is a match. Afterwards, the current position moved back to the
- * location in the input where the lookahead test began.
- *
- * NotExpr - Negative lookahead assertion. The single child expression is tested against the input,
- * and evaluation succeeds if the child *fails* to match. Afterwards, the current position moved
- * back to the location in the input where the lookahead test began.
- *
- * OptExpr - The input is consumed if it matches, otherwise the position is left unchanged. In
- * either case, the evaluation succeeds.
- *
- * StarExpr - The child expression is repeatedly evaluated against the input until no more matches
- * occur. The evaluation always suceeds. The result is a list of 1 or more nodes.
- *
- * PlusExpr - The child expression is repeatedly evaluated against the input until no more matches
- * occur. The evaluation always suceeds if at least one match was made. The result is a list of
- * 1 or more nodes.
- *
- * IdentExpr - Reference to another rule defined in the grammar. Always has a value, representing
- * the name of the rule, and when the grammar resolution algorithm (not yet implemented) is run,
- * will have a single child pointing to the expression associated with the referenced rule.
- *
- * LitExpr - Literal match against a sequence of characters. Always has a value, representing
- * the string to be matched, and has no child nodes.
- *
- * Class - Character class expression. Matches against any characters given in the children,
- * all of which are range expressions.
- *
- * RangeExpr - Matches again a character that is between a specified minimum and maximum. Evaluation
- * succeeds if the next input character c is such that start <= c < end.
- *
- * StringExpr - Instructs the parser to construct a single node in the parse tree representing
- * everything within the child expression. Doesn't have any effect on what is or isn't accepted
- * by the parser.
- */
-
-typedef enum {
-    ChoiceExpr,
-    SequenceExpr,
-    AndExpr,
-    NotExpr,
-    OptExpr,
-    StarExpr,
-    PlusExpr,
-    IdentExpr,
-    LitExpr,
-    ClassExpr,
-    DotExpr,
-    RangeExpr,
-    StringExpr,
-} ExprKind;
-
-typedef struct Expression Expression;
-
-const char *ExprKindAsString(ExprKind kind);
-
-Expression *ExpressionNewChoice(int count, Expression **children);
-Expression *ExpressionNewSequence(int count, Expression **children);
-Expression *ExpressionNewAnd(Expression *child);
-Expression *ExpressionNewNot(Expression *child);
-Expression *ExpressionNewOpt(Expression *child);
-Expression *ExpressionNewStar(Expression *child);
-Expression *ExpressionNewPlus(Expression *child);
-Expression *ExpressionNewIdent(const char *ident);
-Expression *ExpressionNewLit(const char *value);
-Expression *ExpressionNewClass(int count, Expression **children);
-Expression *ExpressionNewDot(void);
-Expression *ExpressionNewRange(int lo, int hi);
-Expression *ExpressionNewString(Expression *child);
-void ExpressionFree(Expression *expr);
-void ExpressionPrint(Expression *expr, int highestPrecedence, const char *indent);
-
-ExprKind ExpressionKind(Expression *expr);
-int ExpressionCount(Expression *expr);
-Expression *ExpressionChildAt(Expression *expr, int index);
-
-// Choice
-
-int ExprChoiceCount(Expression *expr);
-Expression *ExprChoiceChildAt(Expression *expr, int index);
-
-// Sequence
-
-int ExprSequenceCount(Expression *expr);
-Expression *ExprSequenceChildAt(Expression *expr, int index);
-
-// And, Not, Opt, Star, Plus
-
-Expression *ExprAndChild(Expression *expr);
-Expression *ExprNotChild(Expression *expr);
-Expression *ExprOptChild(Expression *expr);
-Expression *ExprStarChild(Expression *expr);
-Expression *ExprPlusChild(Expression *expr);
-
-// Ident, Lit
-
-const char *ExprIdentValue(Expression *expr);
-Expression *ExprIdentTarget(Expression *expr);
-void ExprIdentSetTarget(Expression *expr, Expression *target);
-const char *ExprLitValue(Expression *expr);
-
-// Class
-
-int ExprClassCount(Expression *expr);
-Expression *ExprClassChildAt(Expression *expr, int index);
-
-// Range
-
-int ExprRangeStart(Expression *expr);
-int ExprRangeEnd(Expression *expr);
-
-// String
-
-Expression *ExprStringChild(Expression *expr);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Grammar.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Grammar.c b/experiments/flat/src/Grammar.c
deleted file mode 100644
index f015dfb..0000000
--- a/experiments/flat/src/Grammar.c
+++ /dev/null
@@ -1,133 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Grammar.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-typedef struct Rule Rule;
-
-struct Rule {
-    char *name;
-    Expression *expr;
-    Rule *next;
-};
-
-struct Grammar {
-    Rule **nextDef;
-    Rule *defList;
-};
-
-Rule *RuleNew(const char *name, Expression *expr)
-{
-    Rule *def = (Rule *)calloc(1,sizeof(Rule));
-    def->name = strdup(name);
-    def->expr = expr;
-    return def;
-}
-
-void RuleFree(Rule *def)
-{
-    free(def->name);
-    ExpressionFree(def->expr);
-    free(def);
-}
-
-Grammar *GrammarNew(void)
-{
-    Grammar *gram = (Grammar *)calloc(1,sizeof(Grammar));
-    gram->nextDef = &gram->defList;
-    return gram;
-}
-
-void GrammarFree(Grammar *gram)
-{
-    Rule *next;
-    for (Rule *def = gram->defList; def != NULL; def = next) {
-        next = def->next;
-        RuleFree(def);
-    }
-    free(gram);
-}
-
-void GrammarDefine(Grammar *gram, const char *name, Expression *expr)
-{
-    Rule *def = RuleNew(name,expr);
-    *gram->nextDef = def;
-    gram->nextDef = &def->next;
-}
-
-Expression *GrammarLookup(Grammar *gram, const char *name)
-{
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
-        if (!strcmp(def->name,name))
-            return def->expr;
-    }
-    return NULL;
-}
-
-static void GrammarResolveRecursive(Grammar *gram, Expression *expr, const char *ruleName)
-{
-    if (ExpressionKind(expr) == IdentExpr) {
-        const char *targetName = ExprIdentValue(expr);
-        Expression *targetExpr = GrammarLookup(gram,targetName);
-        if (targetExpr == NULL) {
-            fprintf(stderr,"%s: Cannot resolve reference %s\n",ruleName,targetName);
-            exit(1);
-        }
-        ExprIdentSetTarget(expr,targetExpr);
-    }
-    else {
-        for (int i = 0; i < ExpressionCount(expr); i++)
-            GrammarResolveRecursive(gram,ExpressionChildAt(expr,i),ruleName);
-    }
-}
-
-void GrammarResolve(Grammar *gram)
-{
-    for (Rule *def = gram->defList; def != NULL; def = def->next)
-        GrammarResolveRecursive(gram,def->expr,def->name);
-}
-
-void GrammarPrint(Grammar *gram)
-{
-    int maxNameLen = 0;
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
-        int nameLen = strlen(def->name);
-        if (maxNameLen < nameLen)
-            maxNameLen = nameLen;
-    }
-
-    char *prefix = malloc(maxNameLen+2);
-    memset(prefix,' ',maxNameLen+1);
-    prefix[maxNameLen+1] = '\0';
-
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
-        int nameLen = strlen(def->name);
-        printf("%s",def->name);
-        for (int i = nameLen; i < maxNameLen+1; i++)
-            printf(" ");
-        printf(": ");
-        ExpressionPrint(def->expr,0,prefix);
-        printf(";\n");
-    }
-
-    free(prefix);
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Grammar.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Grammar.h b/experiments/flat/src/Grammar.h
deleted file mode 100644
index e94e51b..0000000
--- a/experiments/flat/src/Grammar.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-#include <sys/types.h>
-
-#include "Expression.h"
-
-typedef struct Grammar Grammar;
-
-Grammar *GrammarNew(void);
-void GrammarFree(Grammar *gram);
-void GrammarDefine(Grammar *gram, const char *name, Expression *expr);
-Expression *GrammarLookup(Grammar *gram, const char *name);
-void GrammarResolve(Grammar *gram);
-void GrammarPrint(Grammar *gram);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Parser.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Parser.c b/experiments/flat/src/Parser.c
deleted file mode 100644
index 74c1e28..0000000
--- a/experiments/flat/src/Parser.c
+++ /dev/null
@@ -1,237 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Parser.h"
-#include "Util.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-typedef struct Parser Parser;
-
-struct Parser {
-    Grammar *gram;
-    const char *input;
-    int start;
-    int end;
-    int pos;
-};
-
-static Term *parseExpr(Parser *p, Expression *expr)
-{
-    int startPos = p->pos;
-    switch (ExpressionKind(expr)) {
-        case ChoiceExpr:
-            for (int i = 0; i < ExprChoiceCount(expr); i++) {
-                Term *term = parseExpr(p,ExprChoiceChildAt(expr,i));
-
-                // If parsing of a choice succeeds, we return immediately.
-                if (term != NULL)
-                    return TermNew(expr,startPos,p->pos,TermListNew(term,NULL)); // Success
-
-                // If parsing of a choice fails, we reset the current position, and continue on with
-                // the next choice (if any). If there are no more choices, the loop complets and
-                // we return NULL.
-                p->pos = startPos;
-            }
-
-            // If we get here, none of the choices have matched, so evaluation of the
-            // choice expression as a whole fails.
-            return NULL; // Failure
-        case SequenceExpr: {
-            TermList *list = NULL;
-            TermList **listEnd = &list;
-            for (int i = 0; i < ExprSequenceCount(expr); i++) {
-                Term *term = parseExpr(p,ExprSequenceChildAt(expr,i));
-
-                // If parsing of a sequence item fails, the sequence as a whole fails. We reset
-                // the current position to the start.
-                if (term == NULL) {
-                    p->pos = startPos;
-                    return NULL; // Failure
-                }
-
-                // If parsing of a sequence item succeeds, we append it to the list of
-                // accumulated child terms, and continue with the next item.
-                TermListPtrAppend(&listEnd,term);
-            }
-
-            // If we get here, all items in the sequence have matched, and evaluation succeeds,
-            // returning a term with children comprising the parse results of all items.
-            return TermNew(expr,startPos,p->pos,list); // Success
-        }
-        case AndExpr: {
-            // Evaluate the child expression to see if it succeeds, but reset the position since
-            // this is a predicate which is not supposed to consume any input. AndExpr is a
-            // positive lookahead assertion, which means it succeeds if and only if the child
-            // evaluation succeeds.
-            Term *term = parseExpr(p,ExprAndChild(expr));
-            p->pos = startPos;
-            if (term != NULL)
-                return TermNew(expr,startPos,startPos,NULL); // Success
-            else
-                return NULL; // Failure
-        }
-        case NotExpr: {
-            // Evaluate the child expression to see if it succeeds, but reset the position since
-            // this is a predicate which is not supposed to consume any input. NotExpr is a
-            // *negative* lookahead assertion, which is the opposite of the above; it succeeds
-            // if and only if the child evaluation *fails*.
-            Term *term = parseExpr(p,ExprNotChild(expr));
-            p->pos = startPos;
-            if (term != NULL)
-                return NULL; // Failure
-            else
-                return TermNew(expr,startPos,startPos,NULL); // Success
-        }
-        case OptExpr: {
-            // An optional expression (? operator) succeeds regardless of whether or not the child
-            // expression succeeds. If the child did succeed, we return its result as a child of the
-            // OptExpr result.
-            Term *term = parseExpr(p,ExprOptChild(expr));
-            TermList *children;
-            if (term != NULL)
-                children = TermListNew(term,NULL);
-            else
-                children = NULL;
-            return TermNew(expr,startPos,p->pos,children); // Success
-        }
-        case StarExpr: {
-            // A zero-or-more expression (* operator) repeatedly matches is child as many times
-            // as possible, suceeding regardless of the number of matches.
-            TermList *list = NULL;
-            TermList **listEnd = &list;
-            for (;;) {
-                Term *term = parseExpr(p,ExprStarChild(expr));
-                if (term == NULL)
-                    break;
-                TermListPtrAppend(&listEnd,term);
-            }
-            return TermNew(expr,startPos,p->pos,list);
-        }
-        case PlusExpr: {
-            // A one-or-more expression (+ operator) operates like a zero-or-match, but fails if
-            // there is not at least one match
-            TermList *list = NULL;
-            TermList **listEnd = &list;
-
-            // First make sure we have at least one match. If this parse fails then we have zero
-            // matches, and thus the plus expression as a whole fails.
-            Term *term = parseExpr(p,ExprPlusChild(expr));
-            if (term == NULL)
-                return NULL; // Failure
-            TermListPtrAppend(&listEnd,term);
-
-            // Now parse any following matches
-            for (;;) {
-                Term *term = parseExpr(p,ExprPlusChild(expr));
-                if (term == NULL)
-                    break;
-                TermListPtrAppend(&listEnd,term);
-            }
-            return TermNew(expr,startPos,p->pos,list); // Success
-        }
-        case IdentExpr: {
-            Term *term = parseExpr(p,ExprIdentTarget(expr));
-            if (term != NULL)
-                return TermNew(expr,startPos,p->pos,TermListNew(term,NULL));
-            else
-                return NULL;
-        }
-        case LitExpr: {
-            const char *value = ExprLitValue(expr);
-            int len = (int)strlen(value);
-            if ((p->pos + len <= p->end) && !memcmp(&p->input[p->pos],value,len)) {
-                p->pos += len;
-                return TermNew(expr,startPos,p->pos,NULL);
-            }
-            else {
-                return NULL;
-            }
-        }
-        case ClassExpr:
-            // Actually identical to ChoiceExpr; we should really merge the two
-            for (int i = 0; i < ExprClassCount(expr); i++) {
-                Term *term = parseExpr(p,ExprClassChildAt(expr,i));
-
-                // If parsing of a choice succeeds, we return immediately.
-                if (term != NULL)
-                    return TermNew(expr,startPos,p->pos,TermListNew(term,NULL)); // Success
-
-                // If parsing of a choice fails, we reset the current position, and continue on with
-                // the next choice (if any). If there are no more choices, the loop complets and
-                // we return NULL.
-                p->pos = startPos;
-            }
-
-            // If we get here, none of the choices have matched, so evaluation of the
-            // choice expression as a whole fails.
-            return NULL; // Failure
-        case DotExpr: {
-            size_t offset = p->pos;
-            int c = UTF8NextChar(p->input,&offset); // FIXME: Should use uint32_t here
-            if (c == 0)
-                return NULL;
-            p->pos = offset;
-            return TermNew(expr,startPos,p->pos,NULL);
-        }
-        case RangeExpr: {
-            size_t offset = p->pos;
-            int c = UTF8NextChar(p->input,&offset); // FIXME: Should use uint32_t here
-            if (c == 0)
-                return NULL;
-            if ((c >= ExprRangeStart(expr)) && (c < ExprRangeEnd(expr))) {
-                p->pos = offset;
-                return TermNew(expr,startPos,p->pos,NULL);
-            }
-            else {
-                return NULL;
-            }
-        }
-        case StringExpr: {
-            Term *term = parseExpr(p,ExprStringChild(expr));
-            if (term == NULL)
-                return NULL;
-            // We ignore the parsed term here, since we're only interested in the string content
-            // (which can be recovered from the input, and the start and end fields of the term).
-            return TermNew(expr,startPos,p->pos,NULL);
-        }
-    }
-    assert(!"unknown expression type");
-    return NULL;
-}
-
-Term *parse(Grammar *gram, const char *rule, const char *input, int start, int end)
-{
-    Expression *rootExpr = GrammarLookup(gram,rule);
-    if (rootExpr == NULL) {
-        fprintf(stderr,"%s: No such rule\n",rule);
-        exit(1);
-    }
-
-    Parser *p = (Parser *)calloc(1,sizeof(Parser));
-    p->gram = gram;
-    p->input = input;
-    p->start = start;
-    p->end = end;
-    p->pos = start;
-    Term *result = parseExpr(p,rootExpr);
-    free(p);
-    return result;
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Parser.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Parser.h b/experiments/flat/src/Parser.h
deleted file mode 100644
index f5feb78..0000000
--- a/experiments/flat/src/Parser.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include "Term.h"
-#include "Grammar.h"
-
-Term *parse(Grammar *gram, const char *rule, const char *input, int start, int end);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Term.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Term.c b/experiments/flat/src/Term.c
deleted file mode 100644
index e3fc44b..0000000
--- a/experiments/flat/src/Term.c
+++ /dev/null
@@ -1,153 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Term.h"
-#include "Util.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-Term *TermNew(Expression *type, int start, int end, TermList *children)
-{
-    assert(type != NULL);
-    Term *term = (Term *)calloc(1,sizeof(Term));
-    term->type = type;
-    term->start = start;
-    term->end = end;
-    term->children = children;
-    return term;
-}
-
-ExprKind TermKind(Term *term)
-{
-    return ExpressionKind(TermType(term));
-}
-
-Expression *TermType(Term *term)
-{
-    return term->type;
-}
-
-int TermStart(Term *term)
-{
-    return term->start;
-}
-
-int TermEnd(Term *term)
-{
-    return term->end;
-}
-
-TermList *TermChildren(Term *term)
-{
-    return term->children;
-}
-
-int TermCount(Term *term)
-{
-    int count = 0;
-    for (TermList *item = term->children; item != NULL; item = item->next)
-        count++;
-    return count;
-}
-
-Term *TermChildAt(Term *term, int index)
-{
-    int count = 0;
-    for (TermList *item = term->children; item != NULL; item = item->next) {
-        if (count == index)
-            return item->term;
-        count++;
-    }
-    fprintf(stderr,"No child term of %s at index %d; max %d\n",ExprKindAsString(TermKind(term)),index,TermCount(term));
-    abort();
-    return NULL;
-}
-
-
-TermList *TermListNew(Term *term, TermList *next)
-{
-    TermList *list = (TermList *)calloc(1,sizeof(TermList));
-    list->term = term;
-    list->next = next;
-    return list;
-}
-
-void TermListPtrAppend(TermList ***listPtr, Term *term)
-{
-    assert(term != NULL);
-    assert(listPtr != NULL);
-    assert(*listPtr != NULL);
-    assert(**listPtr == NULL);
-    **listPtr = TermListNew(term,NULL);
-    *listPtr = &(**listPtr)->next;
-}
-
-void TermPrint(Term *term, const char *input, const char *indent)
-{
-    switch (ExpressionKind(term->type)) {
-        case IdentExpr:
-            printf("%s %s\n",ExprKindAsString(ExpressionKind(term->type)),ExprIdentValue(term->type));
-            break;
-        case LitExpr:
-        case RangeExpr:
-        case DotExpr:
-        case StringExpr: {
-            int start = term->start;
-            int end = term->end;
-            int inputLen = strlen(input);
-            if ((start >= 0) && (start <= inputLen) && (end >= 0) && (end <= inputLen) && (start <= end)) {
-                char *temp = (char*)malloc(end-start+1);
-                memcpy(temp,&input[start],end-start);
-                temp[end-start] = '\0';
-
-                printf("%s ",ExprKindAsString(ExpressionKind(term->type)));
-                printLiteral(temp);
-                printf("\n");
-
-                free(temp);
-            }
-            else {
-                printf("%s\n",ExprKindAsString(ExpressionKind(term->type)));
-            }
-            break;
-        }
-        default:
-            printf("%s\n",ExprKindAsString(ExpressionKind(term->type)));
-            break;
-    }
-
-    int indentLen = strlen(indent);
-    char *nextIndent = (char *)malloc(indentLen+5);
-
-    for (TermList *child = term->children; child != NULL; child = child->next) {
-        if (child->next != NULL) {
-            printf("%s|-- ",indent);
-            snprintf(nextIndent,indentLen+5,"%s|   ",indent);
-            TermPrint(child->term,input,nextIndent);
-        }
-        else {
-            printf("%s\\-- ",indent);
-            snprintf(nextIndent,indentLen+5,"%s    ",indent);
-            TermPrint(child->term,input,nextIndent);
-        }
-    }
-
-    free(nextIndent);
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Term.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Term.h b/experiments/flat/src/Term.h
deleted file mode 100644
index b2a74a8..0000000
--- a/experiments/flat/src/Term.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include "Expression.h"
-
-typedef struct Term Term;
-typedef struct TermList TermList;
-
-struct Term {
-    Expression *type;
-    int start;
-    int end;
-    TermList *children;
-};
-
-struct TermList {
-    Term *term;
-    TermList *next;
-};
-
-Term *TermNew(Expression *type, int start, int end, TermList *children);
-
-ExprKind TermKind(Term *term);
-Expression *TermType(Term *term);
-int TermStart(Term *term);
-int TermEnd(Term *term);
-TermList *TermChildren(Term *term);
-int TermCount(Term *term);
-Term *TermChildAt(Term *term, int index);
-
-TermList *TermListNew(Term *term, TermList *next);
-void TermListPtrAppend(TermList ***listPtr, Term *term);
-
-void TermPrint(Term *term, const char *input, const char *indent);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f937dc73/experiments/flat/src/Util.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Util.c b/experiments/flat/src/Util.c
deleted file mode 100644
index 5c53057..0000000
--- a/experiments/flat/src/Util.c
+++ /dev/null
@@ -1,123 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "Common.h"
-#include "Util.h"
-#include <stdio.h>
-
-#define isstart1(c) (((c) & 0x80) == 0x00) // 0xxxxxxx
-#define isstart2(c) (((c) & 0xE0) == 0xC0) // 110xxxxx
-#define isstart3(c) (((c) & 0xF0) == 0xE0) // 1110xxxx
-#define isstart4(c) (((c) & 0xF8) == 0xF0) // 11110xxx
-#define iscont(c)   (((c) & 0xC0) == 0x80) // 10xxxxxx
-
-uint32_t UTF8NextChar(const char *str, size_t *offsetp)
-{
-    size_t pos = *offsetp;
-    const uint8_t *input = (const uint8_t *)str;
-
-    // If we're part-way through a multi-byte character, skip to the beginning of the next one
-    while ((input[pos] != 0) && iscont(input[pos]))
-        pos++;
-
-    // End of string
-    if (input[pos] == 0) {
-        *offsetp = pos;
-        return 0;
-    }
-
-    if (isstart1(input[pos])) {
-        // 1-byte character: 0xxxxxxx
-        uint32_t a = input[pos];
-        *offsetp = pos+1;
-        return a;
-    }
-    else if (isstart2(input[pos]) && iscont(input[pos+1])) {
-        // 2-byte character: 110xxxxx 10xxxxxx
-        uint32_t a = input[pos+1] & 0x3F; // a = bits 0-5
-        uint32_t b = input[pos+0] & 0x1F; // b = bits 6-10
-        *offsetp = pos+2;
-        return (a << 0) | (b << 6);
-    }
-    else if (isstart3(input[pos]) && iscont(input[pos+1]) && iscont(input[pos+2])) {
-        // 3-byte character: 1110xxxx 10xxxxxx 10xxxxxx
-        uint32_t a = input[pos+2] & 0x3F; // a = bits 0-5
-        uint32_t b = input[pos+1] & 0x3F; // b = bits 6-11
-        uint32_t c = input[pos+0] & 0x0F; // c = bits 12-15
-        *offsetp = pos+3;
-        return (a << 0) | (b << 6) | (c << 12);
-    }
-    else if (isstart4(input[pos]) && iscont(input[pos+1]) && iscont(input[pos+2]) && iscont(input[pos+3])) {
-        // 4-byte character: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-        uint32_t a = input[pos+3] & 0x3F; // a = bits 0-5
-        uint32_t b = input[pos+2] & 0x3F; // b = bits 6-11
-        uint32_t c = input[pos+1] & 0x3F; // c = bits 12-17
-        uint32_t d = input[pos+0] & 0x07; // d = bits 18-20
-        *offsetp = pos+4;
-        return (a << 0) | (b << 6) | (c << 12) | (d << 18);
-    }
-    else {
-        // Invalid UTF8 byte sequence
-        *offsetp = pos;
-        return 0;
-    }
-}
-
-void printEscapedRangeChar(char c)
-{
-    switch (c) {
-        case '[':
-            printf("\\[");
-            break;
-        case ']':
-            printf("\\]");
-            break;
-        case '\\':
-            printf("\\\\");
-            break;
-        default:
-            printf("%c",c);
-            break;
-    }
-}
-
-void printLiteral(const char *value)
-{
-    printf("\"");
-    for (int i = 0; value[i] != '\0'; i++) {
-        switch (value[i]) {
-            case '\r':
-                printf("\\r");
-                break;
-            case '\n':
-                printf("\\n");
-                break;
-            case '\t':
-                printf("\\t");
-                break;
-            case '\"':
-                printf("\\\"");
-                break;
-            case '\\':
-                printf("\\\\");
-                break;
-            default:
-                printf("%c",value[i]);
-        }
-    }
-    printf("\"");
-}



Mime
View raw message