예제 #1
0
        public void PuzzelOne()
        {
            var data = InputParser.ParseString("input_data/day10-1.txt");
            var sut  = new SyntaxChecker(data);

            Assert.Equal(387363, sut.CalculateIncompleteScore());
        }
예제 #2
0
        public void CalculateAutocompleteScoreCorrectly(string input, int expectedScore)
        {
            var sut = new SyntaxChecker(input);

            Assert.Collection(sut.GetAutocompleteScores(),
                              p1 => Assert.Equal(expectedScore, p1));
        }
예제 #3
0
        public void TestInput()
        {
            var data = InputParser.ParseString("input_data/day10-test.txt");
            var sut  = new SyntaxChecker(data);

            Assert.Equal(26397, sut.CalculateIncompleteScore());
        }
예제 #4
0
        public void CalculateAutocompleteCorrectly(string input, string expectedEnding)
        {
            var sut = new SyntaxChecker(input);

            Assert.Collection(sut.GetExpectedEndings(),
                              p1 => Assert.Equal(expectedEnding, p1));
        }
예제 #5
0
        public void SolveSecondPuzzle()
        {
            var sut = new SyntaxChecker(REAL_SUBSYSTEM);

            Assert.True(165561627 < sut.GetAutcompleteScore());
            Assert.Equal(3103006161, sut.GetAutcompleteScore());
        }
예제 #6
0
        public void DetectSyntaxErrorsCorrectly(string input)
        {
            var sut = new SyntaxChecker(input);

            Assert.Collection(sut.GetSyntaxErrors(),
                              p1 => Assert.Equal(input, p1));
        }
예제 #7
0
        public void PuzzelTwo()
        {
            var data = InputParser.ParseString("input_data/day10-1.txt");
            var sut  = new SyntaxChecker(data);

            Assert.Equal(4330777059, sut.AutoCompleteScore());
        }
예제 #8
0
        public void TestInputTwo()
        {
            var data = InputParser.ParseString("input_data/day10-test.txt");
            var sut  = new SyntaxChecker(data);

            Assert.Equal(288957, sut.AutoCompleteScore());
        }
예제 #9
0
        /// <summary>
        /// Converts the text to hex.
        /// </summary>
        private void ConvertHex()
        {
            if (SyntaxChecker.CanParseValue(this.DataType, this.Text))
            {
                this.Text = Conversions.ParsePrimitiveStringAsHexString(this.DataType, this.Text);
            }

            this.SwitchHex();
        }
예제 #10
0
        /// <summary>
        /// Converts a value to an address.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <param name="destinationType">The target type to convert to.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
        {
            if (SyntaxChecker.CanParseValue(DataType.UInt64, value?.ToString()))
            {
                return(Conversions.ToHex(Conversions.ParsePrimitiveStringAsPrimitive(DataType.UInt64, value?.ToString()), formatAsAddress: true, includePrefix: false));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
예제 #11
0
        /// <summary>
        /// Invoked when the convert to decimal menu item is clicked.
        /// </summary>
        /// <param name="sender">Sending object.</param>
        /// <param name="e">Event args.</param>
        private void ConvertToDecMenuItemClick(Object sender, EventArgs e)
        {
            if (SyntaxChecker.CanParseHex(this.ElementType, this.Text))
            {
                this.Text = Conversions.ParseHexStringAsPrimitiveString(this.ElementType, this.Text);
            }

            this.IsHex = false;
        }
예제 #12
0
        /// <summary>
        /// Converts an address string to the corresponding value.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
        {
            if (SyntaxChecker.CanParseAddress(value?.ToString()))
            {
                return(Conversions.AddressToValue(value?.ToString()));
            }

            return(base.ConvertFrom(context, culture, value));
        }
예제 #13
0
        /// <summary>
        /// Converts the text to decimal.
        /// </summary>
        private void ConvertDec()
        {
            if (SyntaxChecker.CanParseHex(this.DataType, this.Text))
            {
                this.Text = Conversions.ParseHexStringAsPrimitiveString(this.DataType, this.Text);
            }

            this.SwitchDec();
        }
예제 #14
0
        private void btnCheckSyntax_Click(object sender, EventArgs e)
        {
            TemplateMain.Instance().ShowOutputText();
            CodeFormatter f = new CodeFormatter(txtText);

            f.ProcessAll(m_codelines);
            SyntaxChecker sc = new SyntaxChecker(m_libraryeditor);

            sc.AddObserver(this);
            sc.ProcessAll(m_codelines);
        }
예제 #15
0
        public void DetectSyntaxErrorsCorrectly_WhenUsingSampleData()
        {
            var sut = new SyntaxChecker(SAMPLE_SUBSYSTEM);

            Assert.Collection(sut.GetSyntaxErrors(),
                              p1 => Assert.Equal("{([(<{}[<>[]}>{[]{[(<()>", p1),
                              p2 => Assert.Equal("[[<[([]))<([[{}[[()]]]", p2),
                              p3 => Assert.Equal("[{[{({}]{}}([{[{{{}}([]", p3),
                              p4 => Assert.Equal("[<(<(<(<{}))><([]([]()", p4),
                              p5 => Assert.Equal("<{([([[(<>()){}]>(<<{{", p5));
        }
예제 #16
0
        private void tbDates_TextChanged(object sender, EventArgs e)
        {
            if (updating || _axis == null)
            {
                return;
            }

            TextBox s = (TextBox)sender;

            if (string.IsNullOrWhiteSpace(s.Text))
            {
                _errorProvider.SetError(s, "Field cannot be blank");
                _errorProvider.Tag = s;
            }
            else if (_errorProvider.Tag == s)
            {
                _errorProvider.Clear();
            }

            try
            {
                //if user enters a date then put
                DateTime dt = DateTime.Parse(s.Text);

                updating = true;
                s.Text   = "'" + dt.ToString("yyyy-MM-dd") + "'";
                updating = false;
            }
            catch (Exception)
            {
            }

            if (s == tbStartDate)
            {
                _axis.StartDate = s.Text;
            }
            else
            {
                _axis.EndDate = s.Text;
            }

            try
            {
                SyntaxChecker.ParityCheckCharacterPairs(new[] { '(', '\'' }, new[] { ')', '\'' }, s.Text);
                s.ForeColor = Color.Black;

                _axis.SaveToDatabase();
                AxisSaved();
            }
            catch (SyntaxErrorException)
            {
                s.ForeColor = Color.Red;
            }
        }
        public void Test_readlines_SyntaxScore_ok()
        {
            var lines = Utils.ReadLinesFromFile("Day10Test.txt");

            Assert.Equal(10, lines.Length);

            var  sut    = new SyntaxChecker(lines);
            long actual = sut.CheckSyntaxScore();

            Assert.Equal(26397, actual);
        }
        public void Day10_Puzzle1_Ok()
        {
            var lines = Utils.ReadLinesFromFile("Day10.txt");

            Assert.Equal(106, lines.Length);

            var  sut    = new SyntaxChecker(lines);
            long actual = sut.CheckSyntaxScore();

            Assert.Equal(323691, actual);
        }
예제 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgramEditor"/> class.
        /// </summary>
        public ProgramEditor()
        {
            syntaxChecker         = new SyntaxChecker();
            intellisense          = new Intellisense(TextArea);
            syntaxCheckVisualizer = new SyntaxCheckVisualizer(this);
            SyntaxCheckerMode     = SyntaxCheckerModeE.OnDemand;

            // Events
            Session.Instance.Highlighting.HighlightingChanged += LoadHighligtingDefinition;
            DataObject.AddPastingHandler(this, OnPaste);
        }
예제 #20
0
        /// <summary>
        /// Hex string to an Int32.
        /// </summary>
        /// <param name="value">Value to be converted.</param>
        /// <param name="targetType">Type to convert to.</param>
        /// <param name="parameter">Optional conversion parameter.</param>
        /// <param name="culture">Globalization info.</param>
        /// <returns>An Int32. If conversion cannot take place, returns 0.</returns>
        public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (SyntaxChecker.CanParseHex(targetType, value.ToString()))
                {
                    return(Conversions.ParseHexStringAsPrimitive(targetType, value.ToString()));
                }
            }

            return(0);
        }
예제 #21
0
        public ICheckerReport CheckSyntax(FormStatement root)
        {
            var typeChecker = new SyntaxChecker();
            var report      = typeChecker.Check(root);

            foreach (var message in report.AllMessages)
            {
                Console.WriteLine(message);
            }

            Console.WriteLine("QL Type check done!");
            return(report);
        }
예제 #22
0
        /// <summary>
        /// Converts a string to the corresponding value type.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
        {
            if (value is String)
            {
                IEnumerable <String> offsetStrings = (value as String).Split(',').Select(offset => offset.Trim());

                if (offsetStrings.All(offset => SyntaxChecker.CanParseHex(DataType.Int32, offset)))
                {
                    return(offsetStrings.Select(offset => (Int32)Conversions.ParseHexStringAsPrimitive(DataType.Int32, offset)).ToArray());
                }
            }

            // Return an invalid object, such that it gets rejected by the property updater -- Note: This exception is not thrown
            return(new ArgumentException());
        }
예제 #23
0
        public void test_SyntaxChecker_validXHTML()
        {
            SBMLNamespaces NS24 = new  SBMLNamespaces(2, 4);
            SBMLNamespaces NS31 = new  SBMLNamespaces(3, 1);
            XMLToken       toptoken;
            XMLNode        topnode;
            XMLTriple      toptriple = new  XMLTriple("notes", "", "");
            XMLToken       token;
            XMLNode        node;
            XMLTriple      triple = new  XMLTriple("p", "", "");
            XMLAttributes  att    = new  XMLAttributes();
            XMLNamespaces  ns     = new  XMLNamespaces();

            ns.add("http://www.w3.org/1999/xhtml", "");
            XMLToken tt = new  XMLToken("This is my text");
            XMLNode  n1 = new XMLNode(tt);

            toptoken = new  XMLToken(toptriple, att);
            topnode  = new XMLNode(toptoken);
            token    = new  XMLToken(triple, att, ns);
            node     = new XMLNode(token);
            node.addChild(n1);
            topnode.addChild(node);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, null) == true);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS24) == true);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS31) == true);
            triple = new  XMLTriple("html", "", "");
            token  = new  XMLToken(triple, att, ns);
            node   = new XMLNode(token);
            node.addChild(n1);
            topnode.removeChild(0);
            topnode.addChild(node);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, null) == true);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS24) == false);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS31) == true);
            triple = new  XMLTriple("html", "", "");
            ns.clear();
            token = new  XMLToken(triple, att, ns);
            node  = new XMLNode(token);
            node.addChild(n1);
            topnode.removeChild(0);
            topnode.addChild(node);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, null) == false);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS24) == false);
            assertTrue(SyntaxChecker.hasExpectedXHTMLSyntax(topnode, NS31) == false);
        }
        // Opens File Dialog
        private static void Open_File()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Title  = "Open RGcode File",
                Filter = "MOD Files (*.mod)| *.mod"
            };

            // Open window and check if file is valid
            if (openFileDialog.ShowDialog() == true)
            {
                modulename = openFileDialog.FileName;
            }

            SyntaxChecker syntax = new SyntaxChecker(modulename);

            syntax.write_metadata();
        }
예제 #25
0
        /// <summary>
        /// Converts a value to the proper dynamic type.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <param name="destinationType">The target type to convert to.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
        {
            String   valueString = (value == null) ? String.Empty : value.ToString();
            DataType dataType    = (value == null) ? null : value.GetType();
            Boolean  isHex       = false;

            if (typeof(AddressItem).IsAssignableFrom(context?.Instance?.GetType()))
            {
                isHex = (context.Instance as AddressItem).IsValueHex;
            }

            if (value == null || !SyntaxChecker.CanParseValue(dataType, valueString))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            return(isHex ? Conversions.ParsePrimitiveAsHexString(dataType, valueString) : valueString);
        }
예제 #26
0
        /// <summary>
        /// Sets the raw value being represented.
        /// </summary>
        /// <param name="value">The raw value.</param>
        public void SetValue(Object value)
        {
            String valueString = value?.ToString();

            if (!SyntaxChecker.CanParseValue(this.DataType, valueString))
            {
                return;
            }

            if (this.IsHex)
            {
                this.Text = Conversions.ParsePrimitiveStringAsHexString(this.DataType, valueString);
            }
            else
            {
                this.Text = valueString;
            }
        }
예제 #27
0
        /// <summary>
        /// Edits a project item based on the project item type.
        /// </summary>
        /// <param name="projectItem">The project item to edit.</param>
        private void EditProjectItem(ProjectItem projectItem)
        {
            if (projectItem is AddressItem)
            {
                ValueEditorModel valueEditor = new ValueEditorModel();
                AddressItem      addressItem = projectItem as AddressItem;
                dynamic          result      = valueEditor.EditValue(null, null, addressItem);

                if (SyntaxChecker.CanParseValue(addressItem.DataType, result?.ToString()))
                {
                    addressItem.AddressValue = result;
                }
            }
            else if (projectItem is ScriptItem)
            {
                ScriptEditorModel scriptEditor = new ScriptEditorModel();
                ScriptItem        scriptItem   = projectItem as ScriptItem;
                scriptItem.Script = scriptEditor.EditValue(null, null, scriptItem.Script) as String;
            }
        }
예제 #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddressItem" /> class.
        /// </summary>
        /// <param name="baseAddress">The base address. This will be added as an offset from the resolved base identifier.</param>
        /// <param name="dataType">The data type of the value at this address.</param>
        /// <param name="description">The description of this address.</param>
        /// <param name="baseIdentifier">The identifier for the base address of this object.</param>
        /// <param name="offsets">The pointer offsets of this address item.</param>
        /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param>
        /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param>
        public AddressItem(
            DataType dataType,
            String description = "New Address",
            Boolean isValueHex = false,
            Object value       = null)
            : base(description)
        {
            // Bypass setters to avoid running setter code
            this.dataType   = dataType;
            this.isValueHex = isValueHex;

            if (!this.isValueHex && SyntaxChecker.CanParseValue(dataType, value?.ToString()))
            {
                this.addressValue = value;
            }
            else if (this.isValueHex && SyntaxChecker.CanParseHex(dataType, value?.ToString()))
            {
                this.addressValue = value;
            }
        }
예제 #29
0
        /// <summary>
        /// Determines if the current text is valid for the current data type.
        /// </summary>
        private void UpdateValidity()
        {
            if (this.IsHex)
            {
                if (SyntaxChecker.CanParseHex(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }
            else
            {
                if (SyntaxChecker.CanParseValue(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }

            this.IsTextValid = false;
            return;
        }
예제 #30
0
        /// <summary>
        /// Converts an address string to the corresponding value.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
        {
            DataType dataType = null;
            Boolean  isHex    = false;

            if (typeof(AddressItem).IsAssignableFrom(context.Instance.GetType()))
            {
                dataType = (context.Instance as AddressItem)?.DataType;
                isHex    = (context.Instance as AddressItem).IsValueHex;
            }

            if (dataType == (DataType)null || !value.GetType().IsAssignableFrom(typeof(String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            if (!(isHex ? SyntaxChecker.CanParseHex(dataType, value as String) : SyntaxChecker.CanParseValue(dataType, value as String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            return(isHex ? Conversions.ParseHexStringAsPrimitive(dataType, value as String) : Conversions.ParsePrimitiveStringAsPrimitive(dataType, value as String));
        }
예제 #31
0
    protected void OnButton1Clicked(object sender, EventArgs e)
    {
        textview4.Buffer.Text = "";
        textview5.Buffer.Text = "";

        Gtk.TextBuffer bfr = textview3.Buffer;
        String stringer = bfr.Text;
        GeneratedCode.symtable = new Dictionary<String, String>();
        GeneratedCode.actions = new LinkedList<GeneratedCode>();

        sc = new SyntaxChecker ();

        String [] arr = stringer.Split ('\n');

        foreach (String a in arr) {
            Boolean tester = false;
            Boolean comment = false;
            String k = a;
            String lexeme;
            String classif;

                foreach (Lexeme l in lexemelist) {

                    Match m = Regex.Match (k, "^" + l.lexeme);

                if (m.Success && tester == false && !(l.lexeme.Equals("R"))) {

                        Gtk.TextBuffer bfr2 = textview4.Buffer;
                        Gtk.TextBuffer bfr3 = textview5.Buffer;
                        tester = true;

                        if (l.classification.Equals ("Variable Identifier") || l.classification.Equals ("Troof Identifier") || l.classification.Equals ("Numbr Identifier") || l.classification.Equals ("Numbar Identifier")) {
                            bfr2.Text = bfr2.Text +m.Value + "\n";
                            lexeme = m.Value;
                        } else {
                            bfr2.Text = bfr2.Text + " " + l.lexeme + "\n";
                        lexeme = l.lexeme;
                        }
                        bfr3.Text = bfr3.Text + " " + l.classification + "\n";
                        classif = l.classification;
                    if (l.classification.Equals ("One Line Comment")) {
                        comment = true;
                    }
                        sc.addtogl (lexeme, classif);
                        k = cutText (k, m.Value);

                        Boolean dumaan = false;
                    Match f = null;

                    while (!Regex.Match (k, "^\\s*$").Success) {

                        dumaan = false;
                        foreach (Lexeme g in lexemelist) {

                            k = k.Trim ();
                            String lex = "^"+g.lexeme;
                            Console.WriteLine ("X=" + lex + "Y="+k);

                            f = Regex.Match (k, lex);

                            if (f.Success && dumaan == false) {

                                if (g.classification.Equals ("Variable Identifier") || g.classification.Equals ("Troof Identifier") || g.classification.Equals ("Numbr Identifier") || g.classification.Equals ("Numbar Identifier")) {
                                    bfr2.Text = bfr2.Text + f.Value + "\n";
                                    lexeme = f.Value;
                                }else {
                                    bfr2.Text = bfr2.Text + " " + g.lexeme + "\n";
                                    lexeme = g.lexeme;
                                }

                                Console.WriteLine (l.classification);

                                if (comment == true) {
                                    bfr3.Text = bfr3.Text + " " + "Comment Block" + "\n";
                                    classif = "Comment Block";
                                }else{
                                bfr3.Text = bfr3.Text + " " + g.classification + "\n";
                                classif = g.classification;
                                }

                                if (g.classification.Equals ("One Line Comment")) {
                                    comment = true;
                                }

                                sc.addtogl (lexeme, classif);
                                k = cutText (k, f.Value);
                                dumaan = true;
                            }
                        }
                    }

                        k = "";
                    }
            }
        }
        textview8.Buffer.Text = "";

        Boolean s = sc.checkSyntax ();
        if (s == false) {
            textview8.Buffer.Text = "SYNTAX ERROR. CANNOT EXECUTE CODE." + "\n";
        } else {
            Console.WriteLine ("EXECUTING CODE");
            GeneratedCode.output = "";
            foreach (GeneratedCode d in GeneratedCode.actions) {
                d.executeCode ();
            }
            textview8.Buffer.Text = GeneratedCode.output;
        }
    }