FlagIsSet() public method

public FlagIsSet ( LanguageFlags flag ) : bool
flag LanguageFlags
return bool
Ejemplo n.º 1
0
        private void MatchRegularToken()
        {
            if (_grammar.FlagIsSet(LanguageFlags.EmitLineStartToken))
            {
                if (Context.Source.Location.Line > Context.PreviousLineStart.Line)
                {
                    Context.CurrentToken      = Context.Source.CreateToken(_grammar.LineStartTerminal);
                    Context.PreviousLineStart = Context.Source.Location;
                    return;
                }
            }
            //Find matching terminal
            // First, try terminals with explicit "first-char" prefixes, selected by current char in source
            ComputeCurrentTerminals();
            //If we have more than one candidate; let grammar method select
            if (Context.CurrentTerminals.Count > 1)
            {
                _grammar.OnScannerSelectTerminal(Context);
            }

            MatchTerminals();
            //If we don't have a token from terminals, try Grammar's method
            if (Context.CurrentToken == null)
            {
                Context.CurrentToken = _grammar.TryMatch(Context, Context.SourceStream);
            }
            if (Context.CurrentToken is MultiToken)
            {
                UnpackMultiToken();
            }
        }
Ejemplo n.º 2
0
        private ParserAction FindActionForStateAndInput()
        {
            if (Context.CurrentParserState.DefaultAction != null)
            {
                return(Context.CurrentParserState.DefaultAction);
            }
            ParserAction action;
            //First try as keyterm/key symbol; for example if token text = "while", then first try it as a keyword "while";
            // if this does not work, try as an identifier that happens to match a keyword but is in fact identifier
            Token inputToken = Context.CurrentParserInput.Token;

            if (inputToken != null && inputToken.KeyTerm != null)
            {
                var keyTerm = inputToken.KeyTerm;
                if (Context.CurrentParserState.Actions.TryGetValue(keyTerm, out action))
                {
                    #region comments
                    // Ok, we found match as a key term (keyword or special symbol)
                    // Backpatch the token's term. For example in most cases keywords would be recognized as Identifiers by Scanner.
                    // Identifier would also check with SymbolTerms table and set AsSymbol field to SymbolTerminal if there exist
                    // one for token content. So we first find action by Symbol if there is one; if we find action, then we
                    // patch token's main terminal to AsSymbol value.  This is important for recognizing keywords (for colorizing),
                    // and for operator precedence algorithm to work when grammar uses operators like "AND", "OR", etc.
                    //TODO: This might be not quite correct action, and we can run into trouble with some languages that have keywords that
                    // are not reserved words. But proper implementation would require substantial addition to parser code:
                    // when running into errors, we need to check the stack for places where we made this "interpret as Symbol"
                    // decision, roll back the stack and try to reinterpret as identifier
                    #endregion
                    inputToken.SetTerminal(keyTerm);
                    Context.CurrentParserInput.Term          = keyTerm;
                    Context.CurrentParserInput.Precedence    = keyTerm.Precedence;
                    Context.CurrentParserInput.Associativity = keyTerm.Associativity;
                    return(action);
                }
            }
            //Try to get by main Terminal, only if it is not the same as symbol
            if (Context.CurrentParserState.Actions.TryGetValue(Context.CurrentParserInput.Term, out action))
            {
                return(action);
            }
            //If input is EOF and NewLineBeforeEof flag is set, try injecting NewLine into input
            if (Context.CurrentParserInput.Term == _grammar.Eof && _grammar.FlagIsSet(LanguageFlags.NewLineBeforeEOF) &&
                Context.CurrentParserState.Actions.TryGetValue(_grammar.NewLine, out action))
            {
                InjectNewLineToken();
                return(action);
            }//if
            return(null);
        }
Ejemplo n.º 3
0
        private void ComputeCurrentTerminals()
        {
            Context.CurrentTerminals.Clear();
            TerminalList termsForCurrentChar;

            if (!Data.TerminalsLookup.TryGetValue(SourceStream.PreviewChar, out termsForCurrentChar))
            {
                termsForCurrentChar = Data.FallbackTerminals;
            }
            //if we are recovering, previewing or there's no parser state, then return list as is
            if (Context.Status == ParserStatus.Recovering || Context.Status == ParserStatus.Previewing ||
                Context.CurrentParserState == null || Grammar.FlagIsSet(LanguageFlags.DisableScannerParserLink) ||
                Context.Mode == ParseMode.VsLineScan)
            {
                Context.CurrentTerminals.AddRange(termsForCurrentChar);
                return;
            }
            // Try filtering terms by checking with parser which terms it expects;
            var parserState = Context.CurrentParserState;

            foreach (var term in termsForCurrentChar)
            {
                //Note that we check the OutputTerminal with parser, not the term itself;
                //in most cases it is the same as term, but not always
                if (parserState.ExpectedTerminals.Contains(term.OutputTerminal) || Grammar.NonGrammarTerminals.Contains(term))
                {
                    Context.CurrentTerminals.Add(term);
                }
            }
        }//method
Ejemplo n.º 4
0
 public override void Init(Irony.Parsing.GrammarData grammarData)
 {
     base.Init(grammarData);
     //Check that Parser-scanner link is enabled - this terminal can be used only if this link is enabled
     if (Grammar.FlagIsSet(LanguageFlags.DisableScannerParserLink))
     {
         grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrImpliedOpUseParserLink, this.Name);
     }
     //"ImpliedSymbolTerminal cannot be used in grammar with DisableScannerParserLink flag set"
 }
Ejemplo n.º 5
0
        public override void Init(GrammarData grammarData)
        {
            base.Init(grammarData);
            //By default for Literal terminals assign node type in Grammar.DefaultLiteralNodeType
            bool assignLiteralType = (AstNodeType == null && AstNodeCreator == null &&
                                      FlagIsSet(TermFlags.IsLiteral) && Grammar.FlagIsSet(LanguageFlags.CreateAst));

            if (assignLiteralType)
            {
                AstNodeType = this.Grammar.DefaultLiteralNodeType;
            }
        }
Ejemplo n.º 6
0
 private bool NeedLineStartToken(SourceLocation forLocation)
 {
     return(Grammar.FlagIsSet(LanguageFlags.EmitLineStartToken) && forLocation.Line > Context.PreviousLineStart.Line);
 }