예제 #1
0
        protected Tuple <Token <T>, Token <T>, Token <T> > BasicTypedShakerFunction(
            Token <T> target,
            TypedShakeCondition <T> cond,
            TypedShakeSelector <T> selector)
        {
            Func <TypedSegment, Token <T>, int> getRest          = (seg, hunk) => (hunk.Length - (seg.Start + seg.Length));
            Func <TypedSegment, int>            getComputedStart = (seg) => seg.Start + seg.Length;

            TypedSegment result = cond(target);

            if (result == null)
            {
                return(new Tuple <Token <T>, Token <T>, Token <T> >(null, null, target));
            }
            else
            {
                TypedSegment restSection = new TypedSegment(getRest(result, target), string.Empty, getComputedStart(result));
                var          matchTokens = selector(result, target);
                var          before      = matchTokens.Item1;
                var          match       = matchTokens.Item2;
                match.IsBig = false;
                var restTokens = selector(restSection, target);
                var rest       = restTokens.Item2;
                rest.IsBig = true;
                return(new Tuple <Token <T>, Token <T>, Token <T> >(before, match, rest));
            }
        }
예제 #2
0
 public EnhancedLR1ParsableLanguage(
     Language lang,
     TypedShakeSelector <string> selector,
     Parser <Rule, ulong> parser,
     Func <Token <string>, bool> shouldKeep)
     : base(lang, selector, parser, shouldKeep)
 {
 }
예제 #3
0
 public ParsableLanguage(
     Language lang,
     TypedShakeSelector <string> selector,
     Parser <R, Encoding> parser,
     Func <Token <string>, bool> shouldKeep)
 {
     this.shouldKeep = shouldKeep;
     this.lang       = lang;
     this.parser     = parser;
     this.tok        = new TokenShakerContainer <string>(selector);
 }
예제 #4
0
 public EnhancedLR1ParsableLanguage(
     Language l,
     TypedShakeSelector <string> selector,
     EnhancedGrammar g,
     string terminateSymbol,
     EnhancedParsingTable table,
     SemanticRule onAccept,
     Func <Token <string>, bool> shouldKeep)
     : this(l, selector,
            new EnhancedLR1Parser(g, terminateSymbol, table, onAccept),
            shouldKeep)
 {
 }
예제 #5
0
 public LR1ParsableLanguage(
     Language l,
     TypedShakeSelector <string> selector,
     Cortex.Grammar.Grammar g,
     string terminateSymbol,
     SemanticRule onAccept,
     bool supressMessages,
     Func <Token <string>, bool> shouldKeep)
     : this(l, selector,
            new LR1Parser(g, terminateSymbol, onAccept, supressMessages),
            shouldKeep)
 {
 }
예제 #6
0
 public LR1ParsableLanguage(
     Language l,
     TypedShakeSelector <string> selector,
     Cortex.Grammar.Grammar g,
     string terminateSymbol,
     LR1ParsingTable table,
     LR1GotoTable gotoTable,
     SemanticRule onAccept,
     Func <Token <string>, bool> shouldKeep)
     : this(l, selector,
            new LR1Parser(g, terminateSymbol, table, gotoTable, onAccept),
            shouldKeep)
 {
 }
예제 #7
0
 public EnhancedLR1ParsableLanguage(
     string name,
     string version,
     string idType,
     IEnumerable <Comment> comments,
     IEnumerable <Symbol> symbols,
     IEnumerable <RegexSymbol> regexSymbols,
     IEnumerable <Keyword> keywords,
     TypedShakeSelector <string> selector,
     EnhancedGrammar g,
     string terminateSymbol,
     SemanticRule onAccept,
     bool supressMessages,
     Func <Token <string>, bool> shouldKeep)
     : this(new Language(name, version, idType,
                         comments, symbols, regexSymbols,
                         keywords), selector, g, terminateSymbol, onAccept, supressMessages,
            shouldKeep)
 {
 }
예제 #8
0
 public LR1ParsableLanguage(
     string name,
     string version,
     string idType,
     IEnumerable <Comment> comments,
     IEnumerable <Symbol> symbols,
     IEnumerable <RegexSymbol> regexSymbols,
     IEnumerable <Keyword> keywords,
     TypedShakeSelector <string> selector,
     Cortex.Grammar.Grammar g,
     string terminateSymbol,
     LR1ParsingTable table,
     LR1GotoTable gotoTable,
     SemanticRule onAccept,
     Func <Token <string>, bool> shouldKeep)
     : this(new Language(name, version, idType,
                         comments, symbols, regexSymbols,
                         keywords), selector, g, terminateSymbol, table, gotoTable, onAccept,
            shouldKeep)
 {
 }
예제 #9
0
        public IEnumerable <Token <T> > TypedShake(Token <T> target, TypedShakeCondition <T> cond, TypedShakeSelector <T> selector)
        {
            Token <T> prev = target;
            Tuple <Token <T>, Token <T>, Token <T> > curr = new Tuple <Token <T>, Token <T>, Token <T> >(null, null, target);

            do
            {
                curr = BasicTypedShakerFunction(curr.Item3, cond, selector);
                if (curr.Item1 != null)
                {
                    if (!curr.Item1.IsBig)
                    {
                        curr.Item1.IsBig = true;
                    }
                    yield return(curr.Item1);
                }
                if (curr.Item2 != null)
                {
                    yield return(curr.Item2);
                }
                if (curr.Item3.Equals((Hunk <T>)prev))
                {
                    if (curr.Item3.Length > 0)
                    {
                        if (!curr.Item3.IsBig)
                        {
                            curr.Item3.IsBig = true;
                        }
                        yield return(curr.Item3);
                    }
                    yield break;
                }
                prev = curr.Item3;
            } while (true);
        }
예제 #10
0
 public TokenShakerContainer(TypedShakeSelector <T> selector)
     : base(null) //compat
 {
     Selector = selector;
 }
예제 #11
0
        private static Tuple <Hunk <T>, Hunk <T> > CompatibilitySelector(Segment seg, Hunk <T> hunk, TypedShakeSelector <T> selector)
        {
            var r = selector(new TypedSegment(seg, string.Empty), new Token <T>(hunk));

            return(new Tuple <Hunk <T>, Hunk <T> >(r.Item1, r.Item2));
        }