static string[] SplitCommand(string cmd) { var result = new List <string>(); var tmp = new StringBuilder(); var ystr = new YString(); for (int i = 0; i < cmd.Length; ++i) { if (char.IsWhiteSpace(cmd[i])) { string s = tmp.ToString(); if (!string.IsNullOrWhiteSpace(s)) { ystr.SetEscapedText(s.Trim()); result.Add(ystr.Text); } tmp.Clear(); } else { tmp.Append(cmd[i]); } } { string s = tmp.ToString(); if (!string.IsNullOrWhiteSpace(s)) { ystr.SetEscapedText(s.Trim()); result.Add(ystr.Text); } tmp.Clear(); } return(result.ToArray()); }
public static Value TrimValue(Value value, int maxStringLength) { if (value.Type != Execution.Type.String) { return(value); } return(new Value(YString.Trim(value.String, maxStringLength))); }
public static void Set(YSection section, string type, string name, string value) { #if RELEASE try { #endif switch (type) { case "str": var str = new YString(); str.Name = name; str.Text = value; section.Add(str); break; case "num": var num = new YNumber(); num.Name = name; if (ulong.TryParse(value, out var val1)) { num.UInt64Value = val1; } section.Add(num); break; case "flg": var flg = new YBoolean(); flg.Name = name; if (value.TryToBoolean(out var val2)) { flg.Flag = val2; } section.Add(flg); break; default: // case "nul" var nul = new YNullOrEmpty(); nul.Name = name; section.Add(nul); break; } #if RELEASE } catch (Exception e) { Program.ShowError(e); } #endif }
public override Value Evaluate(MachineState state) { return(new Value(YString.Trim(Value, state.MaxStringLength))); }
public ConstantString(YString value) { Value = value; }
public ConstantString(string value) { Value = new YString(value); }
public static YString BoolAdd(bool a, YString b, int maxStringLength) { return(YString.Add((Number)a, b, maxStringLength)); }
static DocumentGrammar() { Boolean.Rule = Choice( YamlLexer.True.Constant(YBoolean.True), YamlLexer.False.Constant(YBoolean.False)); Null.Rule = YamlLexer.Null.Constant(YNull.Null); Number.Rule = YamlLexer.Number.BindLexeme(YNumber.FromString); QuotedString.Rule = Choice( YamlLexer.SingleQuotedString.BindLexeme(YString.FromQuotedString), YamlLexer.DoubleQuotedString.BindLexeme(YString.FromQuotedString)); UnquotedString.Rule = YamlLexer.UnquotedString.BindLexeme(YString.FromString); AnyString.Rule = Choice(QuotedString, UnquotedString); Alias.Rule = YamlLexer.Alias.BindLexeme(YAlias.FromString); BlockScalarText.Rule = from header in YamlLexer.BlockScalarHeader.Lexeme() from lines in Between( ScopeTokenKind.ScopeBegin.Kind(), OneOrMore(Choice(YamlLexer.BlockScalarLine.Lexeme(), YamlLexer.NewLine.Lexeme())), ScopeTokenKind.ScopeEnd.Kind()) select YString.FromBlockScalar(header, lines); BlockSequence.Rule = OneOrMore(YamlLexer.BlockSequenceItemMarker.Kind().Take(Node)) .Bind(YSequence.FromList); FlowSequence.Rule = Between(YamlLexer.FlowSequenceBegin.Kind(), ZeroOrMore(FlowNode, YamlLexer.FlowItemSeparator.Kind()), YamlLexer.FlowSequenceEnd.Kind()) .Bind(YSequence.FromList); BlockMapping.Rule = OneOrMore(NameValuePair(AnyString, YamlLexer.MappingSeparator.Kind(), Choice(Node, Alias))) .Bind(YMapping.FromDictionary); FlowMapping.Rule = Between( YamlLexer.FlowMappingBegin.Kind(), ZeroOrMore( NameValuePair( AnyString, YamlLexer.MappingSeparator.Kind(), Choice(FlowNode, Alias)), YamlLexer.FlowItemSeparator.Kind()), YamlLexer.FlowMappingEnd.Kind()) .Bind(YMapping.FromDictionary); FlowNode.Rule = from anchor in Optional(YamlLexer.Anchor.Lexeme()) from node in Choice <YNode>( FlowSequence, Attempt(FlowMapping), // enclosed into attempt lest it consumes QuotedString, UnquotedString QuotedString, Number, Boolean, Null, UnquotedString) select YNode.AttachAnchor(node, anchor); BlockNode.Rule = Between( ScopeTokenKind.ScopeBegin.Kind(), from anchor in Optional(YamlLexer.Anchor.Lexeme()) from node in Choice <YNode>( BlockSequence, Attempt(BlockMapping), // enclosed into attempt lest it consumes QuotedString, UnquotedString QuotedString, Number, Boolean, Null, BlockScalarText, UnquotedString) select YNode.AttachAnchor(node, anchor), ScopeTokenKind.ScopeEnd.Kind()); Node.Rule = Choice(FlowNode, BlockNode); TagDirective.Rule = YamlLexer.TagDirective.BindLexeme(YTagDirective.FromLexeme); YamlVersionDirective.Rule = YamlLexer.VersionDirective.BindLexeme(YVersionDirective.FromLexeme); Directive.Rule = Choice <YDirective>(TagDirective, YamlVersionDirective); BareDocument.Rule = Node.Bind(YDocument.FromBareNode); ExplicitDocument.Rule = YamlLexer.DirectivesEndMarker.Kind().Take(Optional(Node)).Bind(YDocument.FromBareNode); DirectivesDocument.Rule = from directives in OneOrMore(Directive) from body in YamlLexer.DirectivesEndMarker.Kind().Take(Node) select YDocument.Create(directives, body); Document.Rule = OccupiesEntireInput(Choice(DirectivesDocument, ExplicitDocument, BareDocument).ThenSkip(Optional(YamlLexer.DocumentEndMarker.Lexeme()))); }