Ejemplo n.º 1
0
        internal Lexer(SourceUnit unit, HappyLanguageContext languageContext)
        {
            _reader = new InputReader(unit);
            _errorCollector = new ErrorCollector(languageContext.ErrorSink);
            PushState(LexerMode.LexingStatement);

            _keywords["if"] = HappyTokenKind.KeywordIf;
            _keywords["else"] = HappyTokenKind.KeywordElse;
            _keywords["while"] = HappyTokenKind.KeywordWhile;
            _keywords["for"] = HappyTokenKind.KeywordFor;
            _keywords["in"] = HappyTokenKind.KeywordIn;
            _keywords["between"] = HappyTokenKind.KeywordBetween;
            _keywords["where"] = HappyTokenKind.KeywordWhere;
            _keywords["lookup"] = HappyTokenKind.KeywordLookup;
            _keywords["default"] = HappyTokenKind.KeywordDefault;
            _keywords["true"] = HappyTokenKind.LiteralBool;
            _keywords["false"] = HappyTokenKind.LiteralBool;
            _keywords["return"] = HappyTokenKind.KeywordReturn;
            _keywords["def"] = HappyTokenKind.KeywordDef;
            _keywords["null"] = HappyTokenKind.LiteralNull;
            _keywords["load"] = HappyTokenKind.KeywordLoad;
            _keywords["use"] = HappyTokenKind.KeywordUse;
            _keywords["new"] = HappyTokenKind.KeywordNew;
            _keywords["function"] = HappyTokenKind.KeywordFunction;
            _keywords["break"] = HappyTokenKind.KeywordBreak;
            _keywords["continue"] = HappyTokenKind.KeywordContinue;
            _keywords["switch"] = HappyTokenKind.KeywordSwitch;
            _keywords["case"] = HappyTokenKind.KeywordCase;
        }
Ejemplo n.º 2
0
 public static Module ParseModule(SourceUnit sourceUnit, HappyLanguageContext languageContext)
 {
     Lexer lexer = new Lexer(sourceUnit, languageContext);
     Parser parser = new Parser(lexer, languageContext);
     Module retval = null;
     try
     {
         retval = parser.Parse();
     }
     catch(AbortParseException)
     {
         //Left blank intentionally because AbortParseExceptions should never
         //be allowed to bubble up to the caller.
     }
     catch(SyntaxErrorException)
     {
         //We actually want to allow this exception to propogate as-is back
         //to the caller.  This is needed because of the catch-all below
         throw;
     }
     catch(Exception e)
     {
         //All other exceptions are to be considered an internal error
         //We may not know the exact location of the error, but we'll just
         //take the next token out of the lexer to give *some* kind of
         //idea line might contain the error
         DebugAssert.IsNotNull(e);
         Token t = lexer.NextToken();
         throw new InternalSourceException(e, t.Location,
             "The parser threw an unhandled exception.  This is usually caused by a syntax error " +
             "in the script being parsed.  The error ocurred at or before the this locaiton.");
     }
     return retval;
 }
Ejemplo n.º 3
0
 public AstAnalyzer(HappyLanguageContext languageContext)
     : base(VisitorMode.VisitNodeAndChildren)
 {
     _languageContext = languageContext;
     _errorCollector = new ErrorCollector(languageContext.ErrorSink);
     _runtimeContextExp = Expression.Parameter(typeof(HappyRuntimeContext), RuntimeContextIdentifier);
     _globalScopeExp = this.PropertyOrFieldGet("Globals", _runtimeContextExp);
 }
Ejemplo n.º 4
0
        public void SetUp()
        {
            var configFile = Path.GetFullPath(Uri.UnescapeDataString(new Uri(typeof(TestFixtureBase).Assembly.CodeBase).AbsolutePath)) + ".config";
            Runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));

            _output = new MemoryStream();
            _errorOutput = new MemoryStream();

            Runtime.IO.SetOutput(_output, Encoding.ASCII);
            Runtime.IO.SetErrorOutput(_errorOutput, Encoding.ASCII);

            Engine = Runtime.GetEngine("ht");

            LanguageContext = HostingHelpers.GetLanguageContext(Engine) as HappyLanguageContext;

            GlobalScope = Engine.CreateScope();

            Assert.IsNotNull(GlobalScope);
        }
Ejemplo n.º 5
0
 public HappyErrorSink(HappyLanguageContext languageContext)
 {
     _languageContext = languageContext;
 }
Ejemplo n.º 6
0
 public LocationScanner(HappyLanguageContext languageContext)
     : base(languageContext)
 {
 }
Ejemplo n.º 7
0
 internal Parser(Lexer lexer, HappyLanguageContext languageContext)
 {
     _lexer = lexer;
     _errorCollector = new ErrorCollector(languageContext.ErrorSink);
 }