Example #1
0
        /// <summary>
        /// Lexer constructor that initializes all the necessary members
        /// </summary>
        /// <param name="provider">Underlaying tokens provider.</param>
        public CollectionLexer(StringReader source, IErrorSink <Span> errors)
        {
            // TODO: should have CompliantLexer a LanguageFeatures !!!

            _provider = new Lexer(source, Encoding.UTF8, errors,
                                  features: LanguageFeatures.Basic,
                                  initialState: Lexer.LexicalStates.INITIAL);
        }
Example #2
0
 public override void Parse(INodesFactory <LangElement, Span> factory, IErrorSink <Span> errors, IErrorRecovery recovery = null)
 {
     using (var source = new StringReader(this.Code))
     {
         _lexer = new CollectionLexer(source, errors);
         ast    = new Parser().Parse(_lexer, factory, _features, errors, recovery);
     }
 }
Example #3
0
        public ZapParser(IErrorSink sink, [NotNull] IDictionary <string, KeyValuePair <ushort, ZOpAttribute> > opcodeDict)
        {
            this.sink       = sink;
            this.opcodeDict = opcodeDict;

            directiveDict = new Dictionary <string, DirectiveParseHandler>
            {
                { ".ALIGN", ParseAlignDirective },
                { ".BYTE", ParseByteDirective },
                { ".CHRSET", ParseChrsetDirective },
                { ".END", ParseEndDirective },
                { ".ENDI", ParseEndiDirective },
                { ".ENDT", ParseEndtDirective },
                { ".FSTR", ParseFstrDirective },
                { ".FUNCT", ParseFunctDirective },
                { ".GSTR", ParseGstrDirective },
                { ".GVAR", ParseGvarDirective },
                { ".INSERT", ParseInsertDirective },
                { ".LANG", ParseLangDirective },
                { ".LEN", ParseLenDirective },
                { ".NEW", ParseNewDirective },
                { ".OBJECT", ParseObjectDirective },
                { ".PROP", ParsePropDirective },
                { ".SOUND", ParseSoundDirective },
                { ".STR", ParseStrDirective },
                { ".STRL", ParseStrlDirective },
                { ".TABLE", ParseTableDirective },
                { ".TIME", ParseTimeDirective },
                { ".VOCBEG", ParseVocbegDirective },
                { ".VOCEND", ParseVocendDirective },
                { ".WORD", ParseWordDirective },
                { ".ZWORD", ParseZwordDirective },

                { ".DEBUG-ACTION", ParseDebugActionDirective },
                { ".DEBUG-ARRAY", ParseDebugArrayDirective },
                { ".DEBUG-ATTR", ParseDebugAttrDirective },
                { ".DEBUG-FILE", ParseDebugFileDirective },
                { ".DEBUG-GLOBAL", ParseDebugGlobalDirective },
                { ".DEBUG-LINE", ParseDebugLineDirective },
                { ".DEBUG-MAP", ParseDebugMapDirective },
                { ".DEBUG-OBJECT", ParseDebugObjectDirective },
                { ".DEBUG-PROP", ParseDebugPropDirective },
                { ".DEBUG-ROUTINE", ParseDebugRoutineDirective },
                { ".DEBUG-ROUTINE-END", ParseDebugRoutineEndDirective },

                { ".DEFSEG", IgnoreDirective },
                { ".ENDSEG", IgnoreDirective },
                { ".OPTIONS", IgnoreDirective },
                { ".PICFILE", IgnoreDirective },
                { ".SEGMENT", IgnoreDirective },

                // TODO: .TRUE and .FALSE?
            };
        }
        public ErrorHandling(
            UserStringBuilder strBldr,
            IErrorSink sink,
            CErrorFactory factory)
        {
            Debug.Assert(factory != null);

            m_userStringBuilder = strBldr;
            m_errorSink         = sink;
            m_errorFactory      = factory;
        }
Example #5
0
        public ErrorHandling(
            UserStringBuilder strBldr,
            IErrorSink sink,
            CErrorFactory factory)
        {
            Debug.Assert(factory != null);

            _userStringBuilder = strBldr;
            _errorSink = sink;
            _errorFactory = factory;
        }
Example #6
0
        /// <summary>
        /// Lexer constructor that initializes all the necessary members
        /// </summary>
        /// <param name="reader">Text reader containing the source code.</param>
        /// <param name="encoding">Source file encoding to convert UTF characters.</param>
        /// <param name="errors">Error sink used to report lexical error.</param>
        /// <param name="features">Allow or disable short oppening tags for PHP.</param>
        /// <param name="positionShift">Starting position of the first token, used during custom restart.</param>
        /// <param name="initialState">Initial state of the lexer, used during custom restart.</param>
        public Lexer(
            System.IO.TextReader reader,
            Encoding encoding,
            IErrorSink <Span> errors   = null,
            LanguageFeatures features  = LanguageFeatures.Basic,
            int positionShift          = 0,
            LexicalStates initialState = LexicalStates.INITIAL)
        {
            _encoding       = encoding ?? Encoding.UTF8;
            _errors         = errors ?? new EmptyErrorSink <Span>();
            _charOffset     = positionShift;
            _allowShortTags = (features & LanguageFeatures.ShortOpenTags) != 0;

            Initialize(reader, initialState);
        }
Example #7
0
        /// <summary>
        /// Lexer constructor that initializes all the necessary members
        /// </summary>
        /// <param name="reader">Text reader containing the source code.</param>
        /// <param name="encoding">Source file encoding to convert UTF characters.</param>
        /// <param name="errors">Error sink used to report lexical error.</param>
        /// <param name="features">Allow or disable short oppening tags for PHP.</param>
        /// <param name="positionShift">Starting position of the first token, used during custom restart.</param>
        /// <param name="initialState">Initial state of the lexer, used during custom restart.</param>
        public Lexer(
            System.IO.TextReader reader,
            Encoding encoding,
            IErrorSink <Span> errors   = null,
            LanguageFeatures features  = LanguageFeatures.Basic,
            int positionShift          = 0,
            LexicalStates initialState = LexicalStates.INITIAL)
        {
            _encoding   = encoding ?? Encoding.UTF8;
            _errors     = errors ?? new EmptyErrorSink <Span>();
            _charOffset = positionShift;
            _features   = features;
            _strings    = StringTable.GetInstance();

            Initialize(reader, initialState);
        }
Example #8
0
        public LangElement Parse(
            ITokenProvider <SemanticValueType, Span> lexer,
            INodesFactory <LangElement, Span> astFactory,
            LanguageFeatures language,
            IErrorSink <Span> errors     = null,
            IErrorRecovery errorRecovery = null,
            int positionShift            = 0)
        {
            if (lexer == null)
            {
                throw new ArgumentNullException(nameof(lexer));
            }

            if (astFactory == null)
            {
                throw new ArgumentNullException(nameof(astFactory));
            }

            // initialization:
            _languageFeatures = language;
            if (errorRecovery != null)
            {
                _lexer = new BufferedLexer(new CompliantLexer(lexer));
            }
            else
            {
                _lexer = new CompliantLexer(lexer);
            }
            _astFactory    = astFactory;
            _errors        = errors ?? new EmptyErrorSink <Span>();
            _errorRecovery = errorRecovery ?? new EmptyErrorRecovery();
            //InitializeFields();

            _currentScope = new Scope(0);

            base.Scanner = _lexer;
            bool accept = base.Parse();

            LangElement result = _astRoot;

            // clean and let GC collect unused AST and other stuff:
            //ClearFields();

            return(result);
        }
Example #9
0
        /// <summary>
        /// Lexer constructor that initializes all the necessary members
        /// </summary>
        /// <param name="reader">Text reader containing the source code.</param>
        /// <param name="encoding">Source file encoding to convert UTF characters.</param>
        /// <param name="errors">Error sink used to report lexical error.</param>
        /// <param name="features">Allow or disable short oppening tags for PHP.</param>
        /// <param name="docBlockFactory">Factory for documentary comment semantic elements.</param>
        /// <param name="positionShift">Starting position of the first token, used during custom restart.</param>
        /// <param name="initialState">Initial state of the lexer, used during custom restart.</param>
        public Lexer(
            System.IO.TextReader reader,
            Encoding encoding,
            IErrorSink <Span> errors         = null,
            LanguageFeatures features        = LanguageFeatures.Basic,
            IDocBlockFactory docBlockFactory = null,
            int positionShift          = 0,
            LexicalStates initialState = LexicalStates.INITIAL)
        {
            _encoding                  = encoding ?? Encoding.UTF8;
            _errors                    = errors ?? new EmptyErrorSink <Span>();
            _docblockFactory           = docBlockFactory ?? DefaultDocBlockFactory.Instance;
            _charOffset                = positionShift;
            _features                  = features;
            _strings                   = StringTable.GetInstance();
            _processDoubleQuotedString = ProcessDoubleQuotedString;

            Initialize(reader, initialState);
        }
Example #10
0
        public void Parse(NodesFactory factory, IErrorSink <Span> errors,
                          IErrorRecovery recovery   = null,
                          LanguageFeatures features = LanguageFeatures.Basic,
                          Lexer.LexicalStates state = Lexer.LexicalStates.INITIAL)
        {
            var parser = new Parser();

            using (var source = new StringReader(SourceText.ToString()))
            {
                using (var provider = new AdditionalSyntaxProvider(
                           new PhpTokenProvider(
                               new Lexer(source, Encoding.UTF8, errors, features, 0, state),
                               this),
                           factory,
                           parser.CreateTypeRef))
                {
                    ast = parser.Parse(provider, factory, features, errors, recovery);
                }
            }
        }
Example #11
0
        public LangElement Parse(
            ITokenProvider <SemanticValueType, Span> lexer,
            INodesFactory <LangElement, Span> astFactory,
            LanguageFeatures language,
            IErrorSink <Span> errors     = null,
            IErrorRecovery errorRecovery = null,
            int positionShift            = 0)
        {
            if (lexer == null)
            {
                throw new ArgumentNullException(nameof(lexer));
            }

            // initialization:

            _languageFeatures = language;
            _lexer            = new CompliantLexer(lexer, language);
            _astFactory       = astFactory ?? throw new ArgumentNullException(nameof(astFactory));
            _errors           = errors ?? new EmptyErrorSink <Span>();

            if (errorRecovery != null)
            {
                _lexer         = new BufferedLexer(_lexer);
                _errorRecovery = errorRecovery;
            }
            else
            {
                _errorRecovery = EmptyErrorRecovery.Instance;
            }
            //InitializeFields();

            _currentScope = new Scope(0);

            base.Scanner = _lexer;
            bool accept = base.Parse();

            //
            return(_astRoot);
        }
 public ResolutionContext(IErrorSink errorSink)
     : base(errorSink)
 {
 }
Example #13
0
 public TypecheckingContext(IErrorSink errorSink)
     : base(errorSink)
 {
 }
Example #14
0
 public CheckingContext(IErrorSink errorSink)
 {
     this.errorSink = errorSink;
 }
Example #15
0
 public ResolutionContext(IErrorSink errorSink)
     : base(errorSink)
 {
 }
Example #16
0
 /// <summary>
 /// Lexer constructor that initializes all the necessary members
 /// </summary>
 /// <param name="provider">Underlaying tokens provider.</param>
 public CollectionLexer(StringReader source, IErrorSink <Span> errors)
 {
     _provider = new Lexer(source, Encoding.UTF8, errors, LanguageFeatures.Basic, 0, Lexer.LexicalStates.INITIAL);
 }
Example #17
0
 public int Resolve(IErrorSink errorSink) {
   ResolutionContext rc = new ResolutionContext(errorSink);
   Resolve(rc);
   return rc.ErrorCount;
 }
Example #18
0
 public override void Parse(INodesFactory <LangElement, Span> factory, IErrorSink <Span> errors, IErrorRecovery recovery = null)
 {
     Parse((NodesFactory)factory, errors, recovery, LanguageFeatures.Basic, Lexer.LexicalStates.INITIAL);
 }
Example #19
0
 public static void Serious([NotNull] IErrorSink sink, [NotNull] string message)
 {
     Serious(sink, null, message);
 }
Example #20
0
 public static void Warn([NotNull] IErrorSink sink, [CanBeNull] ISourceLine node, [NotNull] string message)
 {
     sink.HandleWarning(new Warning(node, message));
 }
Example #21
0
 public static void Serious([NotNull] IErrorSink sink, ISourceLine node, [NotNull] string message)
 {
     sink.HandleSeriousError(new SeriousError(node, message));
 }
Example #22
0
 public static void Serious([NotNull] IErrorSink sink, ISourceLine node, [NotNull] string format,
                            [NotNull] params object[] args)
 {
     Serious(sink, node, string.Format(format, args));
 }
 public CheckingContext(IErrorSink errorSink)
 {
     this.errorSink = errorSink;
     this.errors    = 0;
 }
Example #24
0
 public static void Warn([NotNull] IErrorSink sink, [CanBeNull] ISourceLine node, [NotNull] string format, [NotNull] params object[] args)
 {
     Warn(sink, node, string.Format(format, args));
 }
 public TypecheckingContext(IErrorSink errorSink)
     : base(errorSink)
 {
 }
Example #26
0
 public int Typecheck(IErrorSink errorSink) {
   TypecheckingContext tc = new TypecheckingContext(errorSink);
   Typecheck(tc);
   return tc.ErrorCount;
 }