protected void ParsePropertyDefinition(bool isStatic) { if (!initialized) { WriteDefaultConstructor(); initialized = true; } string propertyName = CurrentToken.Content; if (ExpectIdentifier()) { Output.AppendLine("// Property " + propertyName); JoopToken block = CurrentToken; if (Accept(JoopTokenType.Block)) { // Defined property. A little more complicated. PropertyCompilerScope propertyScope = new PropertyCompilerScope(ClassName, BaseClassName, propertyName, isStatic); ScopeBlock(propertyScope, block); } else if (Expect(TOKEN_SEMICOLON)) { // Automatic property. Output.AppendLine(string.Format( "function get_{0}() {{ return this.$prop_{0}; }}\r\n" + "{1}.get_{0} = get_{0};\r\n" + "function set_{0}(value) {{ this.$prop_{0} = value; }}\r\n" + "{1}.set_{0} = set_{0};\r\n", propertyName, ClassName + (!isStatic ? ".prototype" : ""))); } } }
private void ParseClassDefinition() { // Tentatively keep the current token. string className = CurrentToken.Content; // The next token is the entire identifier of the class, and must match the // identifier regex. if (ExpectIdentifier()) { string baseClassName = null; // Optionally, we can also have a base class. if (Accept(TOKEN_INHERITCLASS)) { baseClassName = ReadFullyQualifiedName(); } // The next token should be an entire code block defining the class. JoopToken classBlockToken = CurrentToken; if (Expect(JoopTokenType.Block)) { ClassCompilerScope compilerScope = new ClassCompilerScope(className, baseClassName); ScopeBlock(compilerScope, classBlockToken); } } }
private void ParseNamespaceDefinition() { string namespaceName = ReadFullyQualifiedName(); // The next token must be a full code block describing the sub-namespace. JoopToken namespaceBlockToken = CurrentToken; if (Expect(JoopTokenType.Block)) { NamespaceCompilerScope compilerScope = new NamespaceCompilerScope(namespaceName); ScopeBlock(compilerScope, namespaceBlockToken); } }
protected virtual void ScopeBlock(JoopCompilerScope childScope, JoopToken block) { childScope.BlockOffset = BlockOffset + block.Index + 1; childScope.Parse(this, this.Output, block.Content); }