コード例 #1
0
ファイル: WordBoolTest.cs プロジェクト: Krixohub/IntoTheCode
        public void ITC10Load()
        {
            var word = new WordBool();

            Util.ParserLoadWord(word, "  true  ", "true", "bool", 2, 6, 8);
            //             123456789

            Util.ParserLoadWord(word, "  false ", "false", "bool", 2, 7, 8);
            //             123456789

            Util.ParserLoadWord(word, "  true", "true", "bool", 2, 6, 6);
            //             123456789
        }
コード例 #2
0
ファイル: WordBoolTest.cs プロジェクト: Krixohub/IntoTheCode
        public void ITC10LoadError()
        {
            var word = new WordBool();

            //                 "1234567890123456
            Util.WordLoadError("  tru4567  ", word, "bool not true",
                               "itc10: Syntax error (testRule). Expecting bool, found 'tru'. Line 1, colomn 3");

            Util.WordLoadError("  fals56  ", word, "bool not false",
                               "itc10: Syntax error (testRule). Expecting bool, found 'fals'. Line 1, colomn 3");

            //                 "1234567890123456
            Util.WordLoadError("   ", word, "bool not found",
                               "itc10: Syntax error (testRule). Expecting bool, found EOF. Line 1, colomn 4");
        }
コード例 #3
0
ファイル: ParserBuilder.cs プロジェクト: Krixohub/IntoTheCode
        private static List <ParserElementBase> BuildExpression(Parser parser, IEnumerable <CodeElement> docNodes, ParserStatus status)
        {
            //string debug1 = "(" + parser.Name + ")".NL() + docNotes.Aggregate("", (s, n) => s + n.ToMarkupProtected(""));

            List <ParserElementBase> elements = new List <ParserElementBase>();

            foreach (CodeElement element in docNodes)
            {
                switch (element.Name)
                {
                case MetaParser.Expression_:
                    if (docNodes.Count() > 1)
                    {
                        status.AddBuildError(() => MessageRes.itc29, element, parser.Name);
                    }

                    return(BuildExpression(parser, element.Codes(), status));

                case MetaParser.Or_________:
                    ParserElementBase  el1, el2;
                    List <CodeElement> orNodes = docNodes.ToList();
                    // find position
                    int pos = 0;
                    while (pos + 2 < orNodes.Count() && orNodes[++pos] != element)
                    {
                    }
                    if (pos < 1 || pos + 2 > orNodes.Count())
                    {
                        status.AddBuildError(() => MessageRes.itc30, element, parser.Name);
                    }

                    if (pos == 1)
                    {
                        el1 = elements[0];
                    }
                    else
                    {
                        el1 = new SetOfElements(elements.ToArray());
                    }

                    var elementElements2 = new List <CodeElement>();
                    for (int i = pos + 1; i < orNodes.Count(); i++)
                    {
                        elementElements2.Add(orNodes[i]);
                    }
                    List <ParserElementBase> elements2 = BuildExpression(parser, elementElements2, status);

                    if (elements2.Count() == 1)
                    {
                        el2 = elements2[0];
                    }
                    else
                    {
                        el2 = new SetOfElements(elements2.ToArray());
                    }
                    return(new List <ParserElementBase> {
                        new Or(el1, el2)
                    });

                case MetaParser.WordIdent__:
                    ParserElementBase elem;
                    switch (element.Value)
                    {
                    case MetaParser.WordString_:
                        elem = new WordString();
                        break;

                    case MetaParser.WordInt____:
                        elem = new WordInt();
                        break;

                    case MetaParser.WordFloat__:
                        elem = new WordFloat();
                        break;

                    case MetaParser.WordIdent__:
                        elem = new WordIdent();
                        break;

                    case MetaParser.WordBool___:
                        elem = new WordBool();
                        break;

                    default:
                        elem = new RuleLink(element.Value);
                        elem.DefinitionCodeElement = element;
                        break;
                    }
                    elements.Add(elem);
                    break;

                case MetaParser.WordSymbol_:
                    elements.Add(new WordSymbol(element.Value));
                    break;

                case MetaParser.Sequence___:
                    elements.Add(new Sequence(BuildExpression(parser, element.Codes(), status).ToArray()));
                    break;

                case MetaParser.Optional___:
                    elements.Add(new Optional(BuildExpression(parser, element.Codes(), status).ToArray()));
                    break;

                case MetaParser.Parentheses:
                    elements.Add(new Parentheses(BuildExpression(parser, element.Codes(), status).ToArray()));
                    break;

                case MetaParser.Comment____:
                    break;

                default:
                    status.AddBuildError(() => MessageRes.itc31, element, element.Name);
                    break;
                }
            }
            return(elements);
        }