示例#1
0
        public override NFAModel ConvertStringLiteral(StringLiteralExpression exp)
        {
            NFAModel literalNfa = new NFAModel();

            NFAState lastState = null;

            foreach (var symbol in exp.Literal)
            {
                var symbolState = new NFAState();
                int cclass      = CompactCharSetManager.GetCompactClass(symbol);
                var symbolEdge  = new NFAEdge(cclass, symbolState);

                if (lastState != null)
                {
                    lastState.AddEdge(symbolEdge);
                }
                else
                {
                    literalNfa.EntryEdge = symbolEdge;
                }

                lastState = symbolState;

                literalNfa.AddState(symbolState);
            }

            literalNfa.TailState = lastState;

            return(literalNfa);
        }
示例#2
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = _typeSystemServices.Map(typeof(DefaultMemberAttribute));

            foreach (Attribute attribute in _typeDefinition.Attributes)
            {
                IConstructor tag = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != tag)
                {
                    if (defaultMemberAttribute == tag.DeclaringType)
                    {
                        StringLiteralExpression memberName = attribute.Arguments[0] as StringLiteralExpression;
                        if (null != memberName)
                        {
                            List buffer = new List();
                            Resolve(buffer, memberName.Value, EntityType.Any);
                            return(NameResolutionService.GetEntityFromList(buffer));
                        }
                    }
                }
            }
            if (null != BaseType)
            {
                return(BaseType.GetDefaultMember());
            }
            return(null);
        }
 public TypeNode Dispatch(ExpressionNode node, List <TypeNode> parameterTypes)
 {
     return(node switch
     {
         IBinaryNumberOperator n => _numberHelper.VisitBinaryNumOp(n, parameterTypes),
         IBinaryBooleanOperator n => _booleanHelper.VisitBinaryBoolOp(n, parameterTypes),
         IBinarySetOperator n => _setHelper.VisitBinarySetOp(n, parameterTypes),
         SubsetExpression n => _setHelper.VisitSubset(n, parameterTypes),
         SetExpression n => _setHelper.VisitSet(n, parameterTypes),
         NotExpression n => _booleanHelper.VisitNot(n, parameterTypes),
         FunctionCallExpression n => _declarationHelper.VisitFunctionCall(n, parameterTypes),
         IdentifierExpression n => _declarationHelper.VisitIdentifier(n, parameterTypes),
         IntegerLiteralExpression _ => _declarationHelper.VisitIntegerLiteral(),
         RealLiteralExpression _ => _declarationHelper.VisitRealLiteral(),
         BooleanLiteralExpression _ => _declarationHelper.VisitBooleanLiteral(),
         StringLiteralExpression _ => _declarationHelper.VisitStringLiteral(),
         EmptySetLiteralExpression _ => _declarationHelper.VisitEmptySetLiteral(),
         AdditionExpression n => _commonOperatorHelper.VisitAddition(n, parameterTypes),
         SubtractionExpression n => _commonOperatorHelper.VisitSubtraction(n, parameterTypes),
         AbsoluteValueExpression n => _commonOperatorHelper.VisitAbsoluteValue(n, parameterTypes),
         IRelationOperator n => _commonOperatorHelper.VisitRelationalOperator(n, parameterTypes),
         IEquivalenceOperator n => _commonOperatorHelper.VisitEquivalenceOperator(n, parameterTypes),
         NegativeExpression n => _numberHelper.VisitNegative(n, parameterTypes),
         ElementExpression n => _commonOperatorHelper.VisitElement(n, parameterTypes),
         ISetGraphField n => _commonOperatorHelper.VisitISetGraphField(n, parameterTypes),
         IFunctionGraphField n => _commonOperatorHelper.VisitIFunctionGraphField(n, parameterTypes),
         GraphExpression n => _commonOperatorHelper.VisitGraph(n, parameterTypes),
         AnonymousFunctionExpression n => _declarationHelper.VisitAnonymousFunction(n, parameterTypes),
         _ => throw new UnimplementedTypeCheckerException(node, "Dispatch"),
     });
        public void StringLiteralExpression_matches_double_quoted_string()
        {
            var expected = new StringLiteralExpression("string", new SourceRange(0, 8, 1, 0));
              var matchResult = EmdGrammar.StringLiteralExpression.ShouldMatchAllOf(@"""string""");

              matchResult.Product.ShouldBeEquivalentTo(expected);
        }
示例#5
0
        public override void OnReferenceExpression(ReferenceExpression node)
        {
            IEntity entity = NameResolutionService.Resolve(node.Name);

            if (entity != null)
            {
                base.OnReferenceExpression(node);
                return;
            }
            if (node.Name.StartsWith("@"))
            {
                string refComponentName             = node.Name.Substring(1);
                StringLiteralExpression literal     = CodeBuilder.CreateStringLiteral(refComponentName);
                ExternalConstructor     constructor =
                    new ExternalConstructor(TypeSystemServices, _componentReferenceConstructor);
                MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, literal);
                node.ParentNode.Replace(node, invocation);
                return;
            }
            else if (node.ParentNode is MethodInvocationExpression)
            {
                MethodInvocationExpression mie = (MethodInvocationExpression)node.ParentNode;
                //Transform the first parameter of Component ctor to string.
                if (mie.Target.ToString() == "Component")
                {
                    StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name);
                    mie.Replace(node, literal);
                    return;
                }
            }
            base.OnReferenceExpression(node);
        }
示例#6
0
        protected virtual void AddDependency(ArrayLiteralExpression dependencies, BinaryExpression binaryExpression)
        {
            StringLiteralExpression dependency;

            //HACK: replace with proper AST method invocation
            if (binaryExpression.Left is StringLiteralExpression)
            {
                dependency = new StringLiteralExpression(string.Format("{0}|{1}",
                                                                       binaryExpression.Left.ToString().Trim('\''),
                                                                       binaryExpression.Right.ToString().Trim('\'')));
            }
            else if (binaryExpression.Left is BinaryExpression)
            {
                var left = (BinaryExpression)binaryExpression.Left;

                var package = left.Left.ToString().Trim('\'');
                var version = left.Right.ToString().Trim('\'');
                var dll     = binaryExpression.Right.ToString().Trim('\'');

                dependency = new StringLiteralExpression(string.Format("{0}|{1}|{2}",
                                                                       package,
                                                                       dll,
                                                                       version));
            }
            else
            {
                throw new ArgumentOutOfRangeException(string.Format("Unknown Expression type {0} passed to RightShiftToMethodCompilerStep.AddDependency", binaryExpression.Left.GetType().Name));
            }


            dependencies.Items.Add(dependency);
        }
        public ParseTreeValue(TypeTokenPair valuePair)
        {
            _typeTokenPair         = valuePair;
            ParsesToConstantValue  = false;
            _exceedsValueTypeRange = null;
            _hashCode            = valuePair.Token.GetHashCode();
            _dateValue           = null;
            _stringConstant      = null;
            IsMismatchExpression = false;

            if (valuePair.ValueType.Equals(Tokens.Date))
            {
                ParsesToConstantValue = LetCoerce.TryCoerce(_typeTokenPair.Token, out _dateValue);
            }
            else if (valuePair.ValueType.Equals(Tokens.String) && IsStringConstant(valuePair.Token))
            {
                _stringConstant       = new StringLiteralExpression(new ConstantExpression(new StringValue(_typeTokenPair.Token)));
                ParsesToConstantValue = true;
            }
            else if (valuePair.ValueType.Equals(Tokens.String) &&
                     TryGetNonPrintingControlCharCompareToken(valuePair.Token, out _))
            {
                ParsesToConstantValue = true;
            }
        }
示例#8
0
        public StringLiteralExpression CreateStringLiteral(string value)
        {
            StringLiteralExpression expression = new StringLiteralExpression(value);

            expression.ExpressionType = _tss.StringType;
            return(expression);
        }
        public static ExportNode GetExportNode(ExpressionNode exprNode)
        {
            StringLiteralExpression stringLitExpr = new StringLiteralExpression("FileName", 0, 0);

            return(new ExportNode(exprNode, stringLitExpr, new List <ExpressionNode>(),
                                  new List <ExpressionNode>(), 0, 0));
        }
 private static Expression ExpandEventIdentifier(StringLiteralExpression eventId)
 {
     if (!String.IsNullOrEmpty(_event_identifier_target))
     {
         return(new MemberReferenceExpression(new ReferenceExpression(_event_identifier_target), eventId.Value));
     }
     return(eventId);
 }
 public override void OnStringLiteralExpression(StringLiteralExpression literal)
 {
     _found = true;
     if ((_skip = _attributesOnly) == false)
     {
         _applied = BuildConfigurationChild(literal);
     }
 }
示例#12
0
        public override void Switch(IAstTransformer transformer, out Node resultingNode)
        {
            StringLiteralExpression thisNode = (StringLiteralExpression)this;
            Expression resultingTypedNode    = thisNode;

            transformer.OnStringLiteralExpression(thisNode, ref resultingTypedNode);
            resultingNode = resultingTypedNode;
        }
示例#13
0
 protected override void VisitStringLiteralExpression(StringLiteralExpression expression)
 {
     CS.IndentInOut(
         "StringLiteralExpression",
         () =>
     {
         CS.Ln($"{Locals.Result} = {Cfg.MatchString}({Cfg.CurName}, \"{CharRep.InCSharp(expression.Value)}\");");
     });
 }
        private static Expression CreateChild(StringLiteralExpression name)
        {
            var child = new MethodInvocationExpression(
                AstUtil.CreateReferenceExpression(typeof(ChildBuilder).FullName)
                );

            child.Arguments.Add(name);
            return(child);
        }
示例#15
0
            protected override void VisitStringLiteralExpression(StringLiteralExpression expression)
            {
                void Write()
                {
                    Writer.Write($"'{CharRep.InText(expression.Value)}'");
                }

                LexSpaced(expression, Write);
            }
        public void LiteralString_String_ReturnsCorrectResult(string input, string expected)
        {
            StringLiteralExpression stringLit    = new StringLiteralExpression(input, 1, 1);
            StringHelper            stringHelper = new StringHelper();

            string res = stringHelper.LiteralString(stringLit, new List <object>());

            Assert.AreEqual(expected, res);
        }
 public override object Visit(StringLiteralExpression node, object obj)
 {
     if (node.Location == ((AstNode)obj).Location || found)
     {
         found = true;
         return(this.table);
     }
     return(base.Visit(node, obj));
 }
示例#18
0
        public static Expression mode(ReferenceExpression expression, BlockExpression action)
        {
            var modename = new StringLiteralExpression(expression.Name);

            return(new MethodInvocationExpression(
                       new ReferenceExpression("ApplyModeSettings"),
                       modename,
                       action
                       ));
        }
        public override Expression Parse(Parser parser, Token token)
        {
            var stringLiteralExpression = new StringLiteralExpression {
                Value = token.Value
            };

            parser.Consume();

            return(stringLiteralExpression);
        }
示例#20
0
        public static Expression install(ReferenceExpression expression,
                                         BlockExpression action)
        {
            var installName = new StringLiteralExpression(expression.Name);

            return(new MethodInvocationExpression(
                       new ReferenceExpression("GetInstallerMeta"),
                       installName,
                       action
                       ));
        }
示例#21
0
            private static StringLiteralExpression String(INode node)
            {
                var builder = new StringBuilder(node.Count);

                foreach (var child in node.Children)
                {
                    var runes = DecodeChar(child);

                    builder.Append(runes);
                }

                return(StringLiteralExpression.From(node, builder.ToString()));
            }
示例#22
0
        protected ExternalDeclaration(TreeType type, AttributeBlockCollection attributes, ModifierCollection modifiers, Location keywordLocation, Location charsetLocation, Charset charset, Location subOrFunctionLocation, SimpleName name, Location libLocation, StringLiteralExpression libLiteral,
                                      Location aliasLocation, StringLiteralExpression aliasLiteral, ParameterCollection parameters, Location asLocation, AttributeBlockCollection resultTypeAttributes, TypeName resultType, Span span, IList <Comment> comments) : base(type, attributes, modifiers, keywordLocation, name, null, parameters, asLocation, resultTypeAttributes, resultType,
                                                                                                                                                                                                                                                                         span, comments)
        {
            SetParent(libLiteral);
            SetParent(aliasLiteral);

            _CharsetLocation       = charsetLocation;
            _Charset               = charset;
            _SubOrFunctionLocation = subOrFunctionLocation;
            _LibLocation           = libLocation;
            _LibLiteral            = libLiteral;
            _AliasLocation         = aliasLocation;
            _AliasLiteral          = aliasLiteral;
        }
        public void AdditionString_StringAndString_ReturnsConcatenatedString(string input1, string input2, string expected)
        {
            StringLiteralExpression strLit1 = new StringLiteralExpression(input1.ToString(), 1, 1);
            StringLiteralExpression strLit2 = new StringLiteralExpression(input2.ToString(), 2, 2);
            AdditionExpression      addExpr = new AdditionExpression(strLit1, strLit2, 1, 1);
            IInterpreterString      parent  = Substitute.For <IInterpreterString>();

            parent.DispatchString(strLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchString(strLit2, Arg.Any <List <object> >()).Returns(input2);
            StringHelper stringHelper = SetUpHelper(parent);

            string res = stringHelper.AdditionString(addExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
示例#24
0
文件: Parser.cs 项目: mirkomaty/NDO
        void Literal(out OqlExpression expression)
        {
            OqlExpression result = null;

            switch (la.kind)
            {
            case 2: {
                Get();
                result = new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture), t.line, t.col);
                break;
            }

            case 3: {
                Get();
                result = new NumberExpression(int.Parse(t.val), t.line, t.col);
                break;
            }

            case 4: {
                Get();
                result = new StringLiteralExpression(t.val, t.line, t.col);
                break;
            }

            case 13: {
                Get();
                result = new NamedConstantExpression("TRUE", t.line, t.col);
                break;
            }

            case 38: {
                Get();
                result = new NamedConstantExpression("FALSE", t.line, t.col);
                break;
            }

            case 12: {
                Get();
                result = new NamedConstantExpression("NULL", t.line, t.col);
                break;
            }

            default: SynErr(45); break;
            }
            expression = result.Simplify();
        }
示例#25
0
        private Expression EnsureUniqueChild(Expression node)
        {
            if (node is StringLiteralExpression)
            {
                StringLiteralExpression name = (StringLiteralExpression)node;
                if (_childContext.ContainsKey(name.Value))
                {
                    node = CreateChild(name);
                }
                else
                {
                    _childContext.Add(name.Value, null);
                }
            }

            return(node);
        }
示例#26
0
        public override void OnReferenceExpression(ReferenceExpression node)
        {
            IEntity entity = NameResolutionService.Resolve(node.Name);

            //search for the left side of a key in a hash literal expression
            if (node.ParentNode is ExpressionPair &&
                ((ExpressionPair)node.ParentNode).First == node &&
                node.ParentNode.ParentNode is HashLiteralExpression)
            {
                ExpressionPair          parent  = (ExpressionPair)node.ParentNode;
                StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name);
                parent.First = literal;
                parent.Replace(node, literal);
                return;
            }
            base.OnReferenceExpression(node);
        }
示例#27
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = _typeSystemServices.Map(Types.DefaultMemberAttribute);

            foreach (Attribute attribute in _typeDefinition.Attributes)
            {
                IConstructor tag = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != tag)
                {
                    if (defaultMemberAttribute == tag.DeclaringType)
                    {
                        StringLiteralExpression memberName = attribute.Arguments[0] as StringLiteralExpression;
                        if (null != memberName)
                        {
                            List buffer = new List();
                            Resolve(buffer, memberName.Value, EntityType.Any);
                            return(NameResolutionService.GetEntityFromList(buffer));
                        }
                    }
                }
            }
            if (_typeDefinition.BaseTypes.Count > 0)
            {
                List buffer = new List();

                foreach (TypeReference baseType in _typeDefinition.BaseTypes)
                {
                    IType   tag           = TypeSystemServices.GetType(baseType);
                    IEntity defaultMember = tag.GetDefaultMember();
                    if (defaultMember != null)
                    {
                        if (tag.IsInterface)
                        {
                            buffer.AddUnique(defaultMember);
                        }
                        else                         //non-interface base class trumps interfaces
                        {
                            return(defaultMember);
                        }
                    }
                }
                return(NameResolutionService.GetEntityFromList(buffer));
            }
            return(null);
        }
示例#28
0
        public void Expression_statement_is_transformed()
        {
            LiteralExpression   exp = new StringLiteralExpression("arg1");
            ExpressionStatement doStuffStatement = new ExpressionStatement(exp);

            MacroStatement fixture = new MacroStatement(new LexicalInfo("test", 1, 1));

            fixture.Name = "DoStuff";
            fixture.Body = new Block();
            fixture.Body.Add(doStuffStatement);

            BlockToArgumentsTransformer transformer = new BlockToArgumentsTransformer("DoStuff");

            transformer.Visit(fixture);

            Assert.Equal(exp, fixture.Arguments[0]);
            Assert.True(fixture.Body.IsEmpty, "MacroStatement block should be empty after transformation.");
        }
示例#29
0
        public static Expression exclude(BlockExpression action)
        {
            var arrayExpression = new ArrayLiteralExpression();

            foreach (Statement statement in action.Body.Statements)
            {
                var stringLiteral =
                    new StringLiteralExpression(
                        ((MethodInvocationExpression)(((ExpressionStatement)(statement)).Expression)).Arguments[0].ToString().Trim(new[] { '\'' }));

                arrayExpression.Items.Add(stringLiteral);
            }

            return(new MethodInvocationExpression(
                       new ReferenceExpression("SetExcludeList"),
                       arrayExpression
                       ));
        }
示例#30
0
 override public void OnExpressionInterpolationExpression(ExpressionInterpolationExpression node)
 {
     Write("\"");
     foreach (Expression arg in node.Expressions)
     {
         StringLiteralExpression s = arg as StringLiteralExpression;
         if (null == s)
         {
             Write("${");
             Visit(arg);
             Write("}");
         }
         else
         {
             WriteStringLiteralContents(s.Value, _writer, false);
         }
     }
     Write("\"");
 }
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            ReferenceExpression reference = node.Target as ReferenceExpression;

            if (reference != null && reference.Name.StartsWith("@"))
            {
                _component = reference;
            }
            else
            {
                _component = AstUtil.CreateMethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(ComponentReference).FullName),
                    node.Target
                    );
            }

            _method = new StringLiteralExpression(node.Name);
            _found  = true;
        }
        public void StringLiteralExpression_should_match_verbatim_string_16()
        {
            var expected = new StringLiteralExpression("string", new SourceRange(0,38,1,0));

              var match = EmdGrammar.StringLiteralExpression.ShouldMatchAllOf(@"````````````````string````````````````");

              match.Product.ShouldBeEquivalentTo(expected);
        }
示例#33
0
 public virtual void Visit(StringLiteralExpression node)
 {
     DefaultVisit(node);
 }