public void TestValidListOfObjectLiterals() { var resolvers = new ObjectLiteral[] { CreateObject("kind", "SourceResolver"), CreateObject("kind", "SourceResolver") }; // lazy because in case there is a _bug_ in the converter, we don't want this auxiliary conversion // to fail first, before the actual unit test (inside the for loop) var myConvertedResolversArrayLazy = Lazy.Create(() => resolvers.Select(r => ConfigurationConverter.Convert <IResolverSettings>(m_context, r)).ToArray()); foreach (var resolversList in GetDifferentListRepresenations(resolvers)) { IConfiguration conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration( m_context, CreateObject("resolvers", resolversList)); XAssert.IsNotNull(conf); AssertAlmostEqualToDefaultConfigurationObject(conf, "Resolvers"); var confResolversArray = conf.Resolvers.ToArray(); XAssert.IsTrue(MyEqual(myConvertedResolversArrayLazy.Value, confResolversArray)); } }
private static electron.Electron.BrowserWindow CreateOptionsWindow() { var options = ObjectLiteral.Create <electron.Electron.BrowserWindowConstructorOptions>(); options.width = 440; options.height = 565; options.title = "Options"; options.icon = node.path.join(node.__dirname, "Assets/Images/app_icon_32.png"); options.skipTaskbar = true; options.parent = Win; options.modal = true; options.show = false; options.maximizable = false; options.minimizable = false; options.resizable = false; // Create the browser window. var optionsWin = new electron.Electron.BrowserWindow(options); SetMainMenuForOptions(optionsWin); SetContextMenu(optionsWin); App.LoadWindow(optionsWin, "Forms/OptionsForm.html"); return(optionsWin); }
private static void CreateMainWindow() { var options = ObjectLiteral.Create <electron.Electron.BrowserWindowConstructorOptions>(); options.width = 600; options.height = 800; options.icon = node.path.join(node.__dirname, "Assets/Images/app_icon_32.png"); options.title = Constants.AppTitle; options.show = false; // Create the browser window. Win = new electron.Electron.BrowserWindow(options); SetContextMenu(Win); App.SetMainMenu(); App.LoadWindow(Win, "Forms/MainForm.html"); Win.on(lit.closed, () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. Win = null; }); Win.on(lit.minimize, () => { Win.setSkipTaskbar(true); }); }
private CommandLineValue ConvertCommandLineValue(ObjectLiteral literal) { // Argument interface definition: // interface Argument {name?: string; value: ArgumentValue | ArgumentValue[];} var value = literal[m_argumentValueField]; // value is not required field but can be null. In this case the argument would be skipped, no error should be emitted. if (value.IsUndefined) { return(default(CommandLineValue)); } if (value.Value is ArrayLiteral arrayValue) { // case: ArgumentValue[] var arrayOfScalarArguments = ConvertArrayOfScalarArguments(arrayValue); return(new CommandLineValue(arrayOfScalarArguments)); } // case: ArgumentValue var scalarArgument = TryConvertScalarArgument(value); if (scalarArgument.IsDefined) { return(new CommandLineValue(scalarArgument)); } throw Converter.UnexpectedTypeException( m_argumentValueField, value, literal, typeof(ArgumentValue), typeof(ArgumentValue[])); }
public void Visit(ObjectLiteral node) { if (node != null) { DoesRequire = true; } }
public void TestClass() { var c = ObjectLiteral.Create <Config3>(); c.id = 1; Assert.AreEqual(1, c.id); Assert.NotNull(c.GetHashCode()); var c2 = ObjectLiteral.Create <Config4>(); c2.id = 2; c2.Name = "Nancy"; Assert.AreEqual(2, c2.id); Assert.AreEqual("Nancy", c2.Name); Assert.NotNull(c2.GetHashCode()); var c21 = ObjectLiteral.Create <Config4>(); c21.id = 2; c21.Name = "Nancy"; Assert.False(c21 == c2); Assert.False(c21.Equals(c2)); Assert.NotNull(c21.GetHashCode()); c21.id = 21; Assert.False(c21 == c2); Assert.False(c21.Equals(c2)); Config3 c3 = ObjectLiteral.Create <Config4>(); c3.id = 3; Assert.AreEqual(3, c3.id); Assert.NotNull(c.GetHashCode()); }
void InitRange() { // ReSharper disable once UnusedVariable dynamic me = this; dynamic root = _root; Window.SetTimeout(() => { if (_wrapper != null) { return; } dynamic options = ObjectLiteral.Create <object>(); options.min = Min; options.max = Max; options.step = Step; options.start = Value; options.onChange = Script.Write <Function>("function(value){ me.OnUIValueChanged(value); };"); _wrapper = root.range(options); }, 1); }
public static Container WithReadModelConvenienceFunctions(this FunctionBody functionBody, Type type) { var excludePropertiesFrom = typeof(IReadModel); var properties = type.GetTypeInfo().GetProperties(); if (excludePropertiesFrom != null) { properties = properties.Where(p => !excludePropertiesFrom.GetProperties().Select(pi => pi.Name).Contains(p.Name)).ToArray(); } foreach (var property in properties) { var functionName = string.Format("matching{0}", property.Name.ToPascalCase()); var propertyName = property.Name.ToCamelCase(); var filter = new ObjectLiteral(); filter.Assign(propertyName).WithLiteral(propertyName); functionBody.Property(functionName, p => p.WithFunction(function => function .WithParameters(propertyName) .Body .Scope("self", scope => scope.FunctionCall(f => f.WithName("instanceMatching").WithParameters(new[] { filter }) ) ) ) ); } return(functionBody); }
public static T GetScriptValueResult <T>(ScriptValue value, bool alwaysReturn) { if (value is Throw) { object error = value.GetValue(null); if (error is Exception) { throw new ScriptException("Error while executing Script", (Exception)error); } throw new ScriptException(error.ToString()); } if ((value is IPassThroughValue && !(value is ReturnValue)) || !(alwaysReturn || value is ReturnValue)) { return(default(T)); } object tmp = value.GetValue(null); ObjectLiteral olit = tmp as ObjectLiteral; Type t = typeof(T); if (olit != null && t.IsInterface) { tmp = olit.Cast(t); } return((T)tmp); }
public ObjectLiteral ParseObjectLiteral() { var ol = new ObjectLiteral { Token = Next() }; Match(TokenType.LeftBrace); while (Next().IsNot(TokenType.RightBrace)) { var key = ParsePropertyName(); Match(TokenType.Colon); var value = ParseAssignmentExpression(); ol.Properties.Add(key, value); if (Next().Is(TokenType.Comma)) { Match(TokenType.Comma); } else { break; } } Match(TokenType.RightBrace); return(ol); }
private static EvaluationResult GroupBy(Context context, ArrayLiteral receiver, EvaluationResult arg, EvaluationStackFrame captures) { var closure = Converter.ExpectClosure(arg); using (var disposableFrame = EvaluationStackFrame.Create(closure.Function, captures.Frame)) { // To avoid warning: access to disposable closure. var frame = disposableFrame; var entry = context.TopStack; var result = receiver.Values.GroupBy(obj => { frame.SetArgument(0, obj); return(context.InvokeClosure(closure, frame)); }); var arr = result.Select(grp => { var grpArrayLit = ArrayLiteral.CreateWithoutCopy(grp.ToArray(), entry.InvocationLocation, entry.Path); var bindings = new List <Binding> { new Binding(StringId.Create(context.FrontEndContext.StringTable, "key"), grp.Key, location: default(LineInfo)), new Binding(StringId.Create(context.FrontEndContext.StringTable, "values"), grpArrayLit, location: default(LineInfo)), }; return(EvaluationResult.Create(ObjectLiteral.Create(bindings, entry.InvocationLocation, entry.Path))); }).ToArray(); return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(arr, entry.InvocationLocation, entry.Path))); } }
/// <summary> /// Factory that converts object literal to an <see cref="Argument" /> instance. /// </summary> public static Argument ObjectLiteralToArgument(StringTable stringTable, ObjectLiteral literal) { Contract.Requires(stringTable != null); Contract.Requires(literal != null); return(GetInstance(stringTable).ConvertArgument(EvaluationResult.Create(literal), -1)); }
private ObjectLiteral CreateObject(string name1, object value1, string name2, object value2) { return (ObjectLiteral.Create(new List <Binding> { new Binding(CreateString(name1), value1, location: default(LineInfo)), new Binding(CreateString(name2), value2, location: default(LineInfo)) }, default(LineInfo), AbsolutePath.Invalid)); }
private Artifact ConvertArtifact(ObjectLiteral literal) { // interface Artifact { value: File | Directory | StaticDirectory; kind: ArtifactKind; } // const enum ArtifactKind { input = 1, output, rewritten, none, vsoHash, fileId }; var kind = Converter.ExpectEnumValue( literal[m_artifactKindField], new ConversionContext(name: m_artifactKindField, objectCtx: literal)); // Values should be in sync, so freely convert numbers. var artifactKind = (ArtifactKind)kind.Value; var value = literal[m_artifactPathField]; var original = literal[m_artifactOriginalField]; var convContext = new ConversionContext(name: m_artifactPathField, objectCtx: literal); Converter.ExpectPathOrFileOrDirectory(value, out FileArtifact file, out DirectoryArtifact directory, out AbsolutePath path, convContext); ThrowConvertExceptionIf <AbsolutePath>(artifactKind == ArtifactKind.Output && !path.IsValid && !directory.IsValid, value, convContext, "Output artifacts must be specified as paths or directories."); ThrowConvertExceptionIf <AbsolutePath>(artifactKind == ArtifactKind.Rewritten && !path.IsValid && !file.IsValid, value, convContext, "Rewritten artifacts must be specified as files if in-place rewrite or as paths otherwise."); ThrowConvertExceptionIf <FileArtifact>(artifactKind == ArtifactKind.VsoHash && !file.IsValid, value, convContext, "VsoHash artifacts must be specified as files."); ThrowConvertExceptionIf <FileArtifact>(artifactKind == ArtifactKind.FileId && !file.IsValid, value, convContext, "FileId artifacts must be specified as files."); ThrowConvertExceptionIf <DirectoryArtifact>(artifactKind == ArtifactKind.SharedOpaque && !directory.IsValid, value, convContext, "Shared opaque must be specified as directories."); ThrowConvertExceptionIf <DirectoryArtifact>(artifactKind == ArtifactKind.DirectoryId && !directory.IsValid, value, convContext, "DirectoryId artifacts must be specified as directories."); var originalFile = original.IsUndefined ? FileArtifact.Invalid : Converter.ExpectFile(original, false, new ConversionContext(name: m_artifactOriginalField, objectCtx: literal)); return(file.IsValid ? new Artifact(artifactKind, file) : (directory.IsValid ? new Artifact(artifactKind, directory) : new Artifact(artifactKind, path, originalFile))); }
private ObjectLiteral ParseObjectLiteral() { ObjectLiteral ret = NewNode <ObjectLiteral>(); NextToken(); bool first = true; while (Token != TokenType.RBRACE) { if (first) { first = false; } else { ExpectToken(TokenType.COMMA); NextToken(); } switch (Token) { case TokenType.STRING: case TokenType.IDENTIFIER: string str = StrVal; NextToken(); if (Token == TokenType.COLON) { NextToken(); ret.Properties.Add(new DataPair <string, ExpressionNode>(str, ParseExpression(1))); } else if (Token == TokenType.LPAREN) { ret.Properties.Add(new DataPair <string, ExpressionNode>(str, ParseObjectLiteralFunction())); } else { UnexpectedToken(); } break; default: UnexpectedToken(); break; } } //check uniqueness of keys List <string> Keys = new List <string>(); foreach (DataPair <string, ExpressionNode> propertie in ret.Properties) { if (Keys.IndexOf(propertie.Key) != -1) { Error("Duplicate key in object literal"); } Keys.Add(propertie.Key); } NextToken(); return(ret); }
private static EvaluationResult WriteFileHelper(Context context, ModuleLiteral env, EvaluationStackFrame args, WriteFileMode mode) { var path = Args.AsPath(args, 0, false); var tags = Args.AsStringArrayOptional(args, 2); var description = Args.AsStringOptional(args, 3); PipData pipData; switch (mode) { case WriteFileMode.WriteFile: var fileContent = Args.AsIs(args, 1); // WriteFile has a separator argument with default newline var separator = Args.AsStringOptional(args, 3) ?? Environment.NewLine; description = Args.AsStringOptional(args, 4); pipData = CreatePipDataForWriteFile(context, fileContent, separator); break; case WriteFileMode.WriteData: var data = Args.AsIs(args, 1); pipData = DataProcessor.ProcessData(context, context.FrontEndContext.PipDataBuilderPool, EvaluationResult.Create(data), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllLines: var lines = Args.AsArrayLiteral(args, 1); var entry = context.TopStack; var newData = ObjectLiteral.Create( new List <Binding> { new Binding(context.Names.DataSeparator, Environment.NewLine, entry.InvocationLocation), new Binding(context.Names.DataContents, lines, entry.InvocationLocation), }, lines.Location, entry.Path); pipData = DataProcessor.ProcessData(context, context.FrontEndContext.PipDataBuilderPool, EvaluationResult.Create(newData), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllText: var text = Args.AsString(args, 1); pipData = DataProcessor.ProcessData(context, context.FrontEndContext.PipDataBuilderPool, EvaluationResult.Create(text), new ConversionContext(pos: 1)); break; default: throw Contract.AssertFailure("Unknown WriteFileMode."); } FileArtifact result; if (!context.GetPipConstructionHelper().TryWriteFile(path, pipData, WriteFileEncoding.Utf8, tags, description, out result)) { // Error has been logged return(EvaluationResult.Error); } return(new EvaluationResult(result)); }
public override bool Walk(ObjectLiteral node) { if (_typedChar == '}' && node.GetEndIndex(_tree.LocationResolver) == _position) { Span = node.GetSpan(_tree.LocationResolver); return(false); } return(base.Walk(node)); }
public void Visit(ObjectLiteral node) { if (node != null) { m_writer.Write('{'); if (node.Properties != null) { // if this is multi-line output, we're going to want to run some checks first // to see if we want to put the array all on one line or put elements on separate lines. var multiLine = false; if (m_settings.OutputMode == OutputMode.MultipleLines) { if (node.Properties.Count > 5 || NotJustPrimitives(node.Properties)) { multiLine = true; } } if (multiLine) { // multiline -- let's pretty it up a bit m_settings.Indent(); try { var first = true; foreach (var property in node.Properties) { if (first) { first = false; } else { m_writer.Write(','); } NewLine(); property.Accept(this); } } finally { m_settings.Unindent(); } NewLine(); } else { node.Properties.Accept(this); } } m_writer.Write('}'); } }
public static void TestEventTemplate() { var person = ObjectLiteral.Create <EmployeeAndCustomer>(); person.Type1.EmployeeId = 5; person.Type2.CustomerId = 3; Assert.AreEqual(person.Type1.EmployeeId, 5); Assert.AreEqual(person.Type2.CustomerId, 3); }
public virtual void Visit(ObjectLiteral node) { if (node != null) { if (node.Properties != null) { node.Properties.Accept(this); } } }
public static void SetMemberValue(this object target, string name, object value, Type explicitType, ScriptValues.ValueType valueType) { object targetObject; bool isEnum; MemberInfo mi = FindMember(target, name, explicitType, out targetObject, out isEnum); ObjectLiteral ojl = targetObject as ObjectLiteral; FunctionLiteral ful = targetObject as FunctionLiteral; IDictionary <string, object> odi = targetObject as IDictionary <string, object>; if (mi == null) { if (ojl != null) { ojl[name] = value; return; } if (ful != null) { ful.SetInitialScopeValue(name, value); return; } if (odi != null) { odi[name] = value; return; } throw new ScriptException(string.Format("Member {0} is not declared on {1}", name, targetObject)); } PropertyInfo pi; FieldInfo fi; if (mi is PropertyInfo && (pi = (PropertyInfo)mi).CanWrite) { pi.SetValue(targetObject, value, null); } else if (mi is FieldInfo && !(fi = (FieldInfo)mi).IsLiteral) { fi.SetValue(targetObject, value); } else if (mi is EventInfo && value is FunctionLiteral) { FunctionLiteral fl = value as FunctionLiteral; EventInfo ev = mi as EventInfo; ev.AddEventHandler(targetObject, fl.CreateDelegate(ev.EventHandlerType)); } else { throw new ScriptException(string.Format("SetValue is not supported for this Member ({0}", name)); } }
private static ObjectLiteral DeepCloneObject(ObjectLiteral obj) { var namedValues = new List <NamedValue>(obj.Count); foreach (var member in obj.Members) { namedValues.Add(new NamedValue(member.Key.Value, DeepCloneValue(member.Value))); } return(ObjectLiteral.Create(namedValues, obj.Location, obj.Path)); }
/// <nodoc /> public AmbientContext(PrimitiveTypes knownTypes) : base(ContextName, knownTypes) { var currentHost = Host.Current; var osName = SymbolAtom.Create(StringTable, "os"); string osValue; switch (currentHost.CurrentOS) { case BuildXL.Interop.OperatingSystem.Win: osValue = "win"; break; case BuildXL.Interop.OperatingSystem.MacOS: osValue = "macOS"; break; case BuildXL.Interop.OperatingSystem.Unix: osValue = "unix"; break; default: throw Contract.AssertFailure("Unhandled HostOS Type"); } var cpuName = SymbolAtom.Create(StringTable, "cpuArchitecture"); string cpuValue; switch (currentHost.CpuArchitecture) { case HostCpuArchitecture.X86: cpuValue = "x86"; break; case HostCpuArchitecture.X64: cpuValue = "x64"; break; default: throw Contract.AssertFailure("Unhandled CpuArchitecture Type"); } var isElevatedName = SymbolAtom.Create(StringTable, "isElevated"); var isElevatedValue = CurrentProcess.IsElevated; m_currentHost = ObjectLiteral.Create( new Binding(osName, osValue, default(LineInfo)), new Binding(cpuName, cpuValue, default(LineInfo)), new Binding(isElevatedName, isElevatedValue, default(LineInfo)) ); MountNameObject = Symbol("name"); MountPathObject = Symbol("path"); }
private static void LoadWindow(electron.Electron.BrowserWindow win, string page) { var windowUrl = ObjectLiteral.Create <node.url.URL>(); windowUrl.pathname = node.path.join(node.__dirname, page); windowUrl.protocol = "file:"; var formattedUrl = node.url.format(windowUrl); // and load the index.html of the app. win.loadURL(formattedUrl); }
internal ObjectLiteral GenObjectLiteral(IScope scope, int maxDepth) { scope.Require(GlobalOverride.OVOF); scope.Require(GlobalOverride.OTST); var ol = new ObjectLiteral(); int propertiesCount = _options.ObjectLiteralSizeRange.RandomValue(_rand); while (propertiesCount-- > 0) { ol.Values.Add(GenLiteral(scope, maxDepth - 1)); } return(ol); }
public virtual object Walk(ObjectLiteral node) { if (Enter(node)) { foreach (var prop in node.Properties) { prop.Key.Accept(this); prop.Value.Accept(this); } } Exit(node); return(null); }
private SealDirectoryContentFilter?GetContentFilterHelper(ObjectLiteral obj) { if (obj == null) { return(null); } var regex = Converter.ExtractRegex(obj, m_sealDirectoryContentFilterRegex, allowUndefined: false); var kindAsString = Converter.ExtractString(obj, m_sealDirectoryContentFilterKind, allowUndefined: false); return(new SealDirectoryContentFilter( (SealDirectoryContentFilter.ContentFilterKind)Enum.Parse(typeof(SealDirectoryContentFilter.ContentFilterKind), kindAsString), regex.ToString())); }
/// <summary> /// Gets the name and location information related to the function name binding for a FunctionObject node /// </summary> private IReadOnlyList <BindingInformation> GetBindings(FunctionObject node) { List <BindingInformation> result = new List <BindingInformation>(); // Gets the name of an object property that a function is bound to, like the static method foo in the example "object.foo = function () {}" if (node.Parent is BinaryOperator parentBinaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(parentBinaryOperator)); return(result); } // Gets the name of an object property that a function is bound to against the prototype, like the instance method foo in the example "object.prototype = {foo: function () {}}" if (node.Parent is ObjectLiteralProperty parentObjectLiteralProperty) { // See if we can get the name of the object that this method belongs to ObjectLiteral objectLiteralParent = parentObjectLiteralProperty.Parent?.Parent as ObjectLiteral; if (objectLiteralParent != null && objectLiteralParent.Parent is BinaryOperator binaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(binaryOperator)); } result.Add( new BindingInformation( name: parentObjectLiteralProperty.Name.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: parentObjectLiteralProperty.Context.StartLineNumber - 1, zeroBasedColumnNumber: parentObjectLiteralProperty.Context.StartColumn))); return(result); } // Gets the name of a variable that a function is bound to, like foo in the example "var foo = function () {}" BindingIdentifier bindingIdentifier = (node.Parent is VariableDeclaration parentVariableDeclaration) ? parentVariableDeclaration.Binding as BindingIdentifier : node.Binding; // Gets the name bound to the function, like foo in the example "function foo() {} if (bindingIdentifier != null) { result.Add( new BindingInformation( name: bindingIdentifier.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: bindingIdentifier.Context.StartLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. zeroBasedColumnNumber: bindingIdentifier.Context.StartColumn))); return(result); } return(null); }
private static ObjectLiteral GetQualifierSpaceValue(EvaluationContext context, QualifierSpaceId qualifierSpaceId) { Contract.Requires(context != null); Contract.Requires(context.FrontEndContext.QualifierTable.IsValidQualifierSpaceId(qualifierSpaceId)); var qualifierSpace = context.FrontEndContext.QualifierTable.GetQualifierSpace(qualifierSpaceId); var bindings = new List <Binding>(qualifierSpace.Keys.Count); foreach (var kvp in qualifierSpace.AsDictionary) { var values = ArrayLiteral.CreateWithoutCopy(kvp.Value.Select(s => EvaluationResult.Create(s.ToString(context.StringTable))).ToArray(), default(LineInfo), AbsolutePath.Invalid); bindings.Add(new Binding(kvp.Key, values, default(LineInfo))); } return(ObjectLiteral.Create(bindings, default(LineInfo), AbsolutePath.Invalid)); }
void UpdateUIValue() { if (_root == null) { return; } dynamic root = _root; dynamic options = ObjectLiteral.Create <object>(); options.maxRating = MaxRate; options.initialRating = Rate; Window.SetTimeout(() => { root.rating(options); }, 5); }
public virtual void Exit(ObjectLiteral node) { }
public virtual bool Enter(ObjectLiteral node) { return true; }
public virtual bool Walk(ObjectLiteral node) { return true; }
public void VisitProperty(ObjectLiteral.Property property) { Assign(property, property.Key.Value, property.Value); }
public void VisitObjectLiteral(ObjectLiteral objectLiteral) { foreach (ObjectLiteral.Property p in objectLiteral.Value) { VisitProperty(p); } ProcessCommentBefore(objectLiteral); ReturnValue = null; }
public ObjectLiteral ParseObjectLiteral() { var ol = new ObjectLiteral {Token = Next()}; Match(TokenType.LeftBrace); while (Next().IsNot(TokenType.RightBrace)) { var key = ParsePropertyName(); Match(TokenType.Colon); var value = ParseAssignmentExpression(); ol.Properties.Add(key, value); if (Next().Is(TokenType.Comma)) Match(TokenType.Comma); else break; } Match(TokenType.RightBrace); return ol; }
public virtual object Walk(ObjectLiteral node) { if (Enter(node)) { foreach (var prop in node.Properties) { prop.Key.Accept(this); prop.Value.Accept(this); } } Exit(node); return null; }
public virtual void PostWalk(ObjectLiteral node) { }
public override bool Enter(ObjectLiteral node) { Print("ObjectLiteral"); level++; return true; }
// $ANTLR start "objectLiteral" // JavaScript.g:349:1: objectLiteral : '{' ( LT )* ( propertyNameAndValue ( ( LT )* ',' ( LT )* propertyNameAndValue )* ( ',' )? ( LT )* )? '}' ; public JavaScriptParser.objectLiteral_return objectLiteral() // throws RecognitionException [1] { JavaScriptParser.objectLiteral_return retval = new JavaScriptParser.objectLiteral_return(); retval.Start = input.LT(1); object root_0 = null; IToken char_literal412 = null; IToken LT413 = null; IToken LT415 = null; IToken char_literal416 = null; IToken LT417 = null; IToken char_literal419 = null; IToken LT420 = null; IToken char_literal421 = null; JavaScriptParser.propertyNameAndValue_return propertyNameAndValue414 = default(JavaScriptParser.propertyNameAndValue_return); JavaScriptParser.propertyNameAndValue_return propertyNameAndValue418 = default(JavaScriptParser.propertyNameAndValue_return); object char_literal412_tree=null; object LT413_tree=null; object LT415_tree=null; object char_literal416_tree=null; object LT417_tree=null; object char_literal419_tree=null; object LT420_tree=null; object char_literal421_tree=null; try { // JavaScript.g:350:2: ( '{' ( LT )* ( propertyNameAndValue ( ( LT )* ',' ( LT )* propertyNameAndValue )* ( ',' )? ( LT )* )? '}' ) // JavaScript.g:350:4: '{' ( LT )* ( propertyNameAndValue ( ( LT )* ',' ( LT )* propertyNameAndValue )* ( ',' )? ( LT )* )? '}' { root_0 = (object)adaptor.GetNilNode(); char_literal412=(IToken)Match(input,40,FOLLOW_40_in_objectLiteral3140); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal412_tree = new ObjectLiteral(char_literal412) ; root_0 = (object)adaptor.BecomeRoot(char_literal412_tree, root_0); } // JavaScript.g:350:26: ( LT )* do { int alt206 = 2; int LA206_0 = input.LA(1); if ( (LA206_0 == LT) ) { alt206 = 1; } switch (alt206) { case 1 : // JavaScript.g:350:26: LT { LT413=(IToken)Match(input,LT,FOLLOW_LT_in_objectLiteral3146); if (state.failed) return retval; } break; default: goto loop206; } } while (true); loop206: ; // Stops C# compiler whining that label 'loop206' has no statements // JavaScript.g:350:29: ( propertyNameAndValue ( ( LT )* ',' ( LT )* propertyNameAndValue )* ( ',' )? ( LT )* )? int alt212 = 2; int LA212_0 = input.LA(1); if ( ((LA212_0 >= Identifier && LA212_0 <= NumericLiteral)) ) { alt212 = 1; } switch (alt212) { case 1 : // JavaScript.g:350:30: propertyNameAndValue ( ( LT )* ',' ( LT )* propertyNameAndValue )* ( ',' )? ( LT )* { PushFollow(FOLLOW_propertyNameAndValue_in_objectLiteral3151); propertyNameAndValue414 = propertyNameAndValue(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, propertyNameAndValue414.Tree); // JavaScript.g:350:51: ( ( LT )* ',' ( LT )* propertyNameAndValue )* do { int alt209 = 2; alt209 = dfa209.Predict(input); switch (alt209) { case 1 : // JavaScript.g:350:52: ( LT )* ',' ( LT )* propertyNameAndValue { // JavaScript.g:350:54: ( LT )* do { int alt207 = 2; int LA207_0 = input.LA(1); if ( (LA207_0 == LT) ) { alt207 = 1; } switch (alt207) { case 1 : // JavaScript.g:350:54: LT { LT415=(IToken)Match(input,LT,FOLLOW_LT_in_objectLiteral3154); if (state.failed) return retval; } break; default: goto loop207; } } while (true); loop207: ; // Stops C# compiler whining that label 'loop207' has no statements char_literal416=(IToken)Match(input,43,FOLLOW_43_in_objectLiteral3158); if (state.failed) return retval; // JavaScript.g:350:64: ( LT )* do { int alt208 = 2; int LA208_0 = input.LA(1); if ( (LA208_0 == LT) ) { alt208 = 1; } switch (alt208) { case 1 : // JavaScript.g:350:64: LT { LT417=(IToken)Match(input,LT,FOLLOW_LT_in_objectLiteral3161); if (state.failed) return retval; } break; default: goto loop208; } } while (true); loop208: ; // Stops C# compiler whining that label 'loop208' has no statements PushFollow(FOLLOW_propertyNameAndValue_in_objectLiteral3165); propertyNameAndValue418 = propertyNameAndValue(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, propertyNameAndValue418.Tree); } break; default: goto loop209; } } while (true); loop209: ; // Stops C# compiler whining that label 'loop209' has no statements // JavaScript.g:350:90: ( ',' )? int alt210 = 2; int LA210_0 = input.LA(1); if ( (LA210_0 == 43) ) { alt210 = 1; } switch (alt210) { case 1 : // JavaScript.g:350:91: ',' { char_literal419=(IToken)Match(input,43,FOLLOW_43_in_objectLiteral3170); if (state.failed) return retval; } break; } // JavaScript.g:350:100: ( LT )* do { int alt211 = 2; int LA211_0 = input.LA(1); if ( (LA211_0 == LT) ) { alt211 = 1; } switch (alt211) { case 1 : // JavaScript.g:350:100: LT { LT420=(IToken)Match(input,LT,FOLLOW_LT_in_objectLiteral3175); if (state.failed) return retval; } break; default: goto loop211; } } while (true); loop211: ; // Stops C# compiler whining that label 'loop211' has no statements } break; } char_literal421=(IToken)Match(input,41,FOLLOW_41_in_objectLiteral3181); if (state.failed) return retval; } retval.Stop = input.LT(-1); if ( (state.backtracking==0) ) { retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);} } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }
public override object Walk(ObjectLiteral node) { var bikeObject = new BikeObject(InterpretationContext.ObjectBase); foreach (var prop in node.Properties) { string name = prop.Key is Identifier ? ((Identifier) prop.Key).Value : ((PrimitiveLiteral) prop.Key).Value; var value = prop.Value.Accept(this); bikeObject.Assign(name, value); if (value is BikeFunction && ((BikeFunction)value).Name.Value == BikeFunction.Anonymous) { ((BikeFunction)value).Name = new BikeString(name); } } return bikeObject; }
public override void Exit(ObjectLiteral node) { level--; }
public virtual void Visit(ObjectLiteral node) { if (node != null) { AcceptChildren(node); } }