예제 #1
0
 public CompilerContext(LanguageCompiler compiler)
 {
     this.Compiler = compiler;
       this.Runtime = compiler.Grammar.CreateRuntime();
     #if DEBUG
       Options |= CompilerOptions.GrammarDebugging;
     #endif
 }
예제 #2
0
        EditorViewAdapterList _viewsCopy; //copy used in refresh loop; set to null when views are added/removed

        #endregion Fields

        #region Constructors

        public EditorAdapter(LanguageCompiler compiler)
        {
            _compiler = compiler;
            _context = new CompilerContext(_compiler);
            _context.Options |= CompilerOptions.CollectTokens | CompilerOptions.MatchBraces;
            _parsedSource = new ParsedSource(String.Empty, new TokenList(), null);
            _colorizerThread = new Thread(ColorizerLoop);
            _colorizerThread.IsBackground = true;
            _parserThread = new Thread(ParserLoop);
            _parserThread.IsBackground = true;
        }
예제 #3
0
 //Used in unit tests
 public static LanguageCompiler CreateDummy()
 {
     LanguageCompiler compiler = new LanguageCompiler(new Grammar());
       return compiler;
 }
예제 #4
0
파일: GraphCLI.cs 프로젝트: TheByte/sones
        private void BuildGraphCLIGrammar()
        {

            #region global grammar options

            GraphCLIGrammar.CaseSensitive = false;

            NonTerminal _Command = new NonTerminal("Command");

            List<ABnfTerm> _SubtreeCommandGrammarRoot = new List<ABnfTerm>();

            #endregion

            #region get command specific grammars

            foreach (KeyValuePair<String, AllCLICommands> _aCommand in Commands)
            {
                //TODO: check if the grammar is valid. if not --> handle error
                Grammar _aCommandGrammar = _aCommand.Value.CommandGrammar;
                LanguageCompiler _testCompiler = new LanguageCompiler(_aCommandGrammar);
                Boolean isGrammarValid = true;

                foreach (String aErrorString in _testCompiler.Grammar.Errors)
                {
                    if (aErrorString.StartsWith("Error"))
                    {
                        WriteLine(aErrorString);
                        isGrammarValid = false;
                    }
                }

                if (isGrammarValid)
                {

                    GraphCLIGrammar.NonTerminals.AddRange(_aCommandGrammar.NonTerminals);

                    GraphCLIGrammar.Terminals.AddRange(_aCommandGrammar.Terminals);

                    _SubtreeCommandGrammarRoot.Add(_aCommandGrammar.Root);
                }
                else
                {
                    WriteLine("ERROR! The command \"{0}\" is defined by an incorrect BNF grammar. It is not integrated into the GraphCLI!");

                }
            }

            #endregion

            #region build new root

            for (int i = 0; i < _SubtreeCommandGrammarRoot.Count; i++)
            {
                BnfExpression _exprNew = new BnfExpression(_SubtreeCommandGrammarRoot[i]);

                if (!i.Equals(0))
                {
                    BnfExpression _exprActual = new BnfExpression(_Command.Rule);
                    
                    _Command.Rule = _exprActual | _exprNew;
                }
                else
                {
                    _Command.Rule = _exprNew;
                }
            }
 
            GraphCLIGrammar.NonTerminals.Add(_Command);

            GraphCLIGrammar.Root = _Command;

            #endregion

        }
예제 #5
0
파일: GraphCLI.cs 프로젝트: TheByte/sones
        private void LoadGrammar(params Type[] myCommandTypes)
        {
            FindAndRegisterCLICommands(myCommandTypes);
            BuildGraphCLIGrammar();
            GraphCLICompiler = new LanguageCompiler(GraphCLIGrammar);

            #region Load Autocompletion

            AutoCompletionTypeNames = new HashSet<string>();
            foreach (Terminal aTerminal in GraphCLIGrammar.Terminals)
            {
                if (aTerminal.GraphOptions.Contains(GraphOption.IsUsedForAutocompletion))
                {
                    AutoCompletionTypeNames.Add(aTerminal.Name);
                }
            }

            LoadAutoCompletion();

            #region Error Handling

            foreach (String aAcName in AutoCompletionTypeNames)
            {
                if (!AutoCompletions.ContainsKey(aAcName.ToLower()))
                {
                    if (_CLI_Output == CLI_Output.Standard)
                        WriteLine("WARNING! \"" + aAcName + "\"" + " Autocompletion is not available.");
                }
            }

            #endregion

            #endregion
        
        }