public KeyValuePair <string, PathType>?CompileCurrent(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { if (CurrentPart == ".") { PathParts.Add(null, PathType.SelfAssignment); } else if (CurrentPart == "../") { PathParts.Add(null, PathType.ParentSelector); } else if (CurrentPart == "~") { PathParts.Add(null, PathType.RootSelector); } else if (CurrentPart == "?") { PathParts.Add(null, PathType.ObjectSelector); } else if (CurrentPart.Trim() != string.Empty) { if (!ComputeCurrentPart(context, index, out errProducer)) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Invalid character")); return(default);
public string GetFormatterName(TokenzierContext context, int index, out bool found, out Func <IMorestachioError> errProducer) { var last = CompileCurrent(context, index, out errProducer); if (last == null) { if (CurrentPart == string.Empty) { last = new KeyValuePair <string, PathType>(string.Empty, PathType.DataPath); } else { found = false; return(null); } } found = true; if (last.Value.Value != PathType.DataPath) { PathParts.Add(last.Value.Key, last.Value.Value); return(string.Empty); } return(last.Value.Key); }
/// <summary> /// Indexes the expression or template and creates a new Context for the given text by indexing all linebreaks /// </summary> /// <returns></returns> public static TokenzierContext FromText(string expression, CultureInfo culture = null) { var tokenzierContext = new TokenzierContext( Tokenizer.FindNewLines(expression).ToArray(), culture); tokenzierContext.SetLocation(0); return(tokenzierContext); }
public IList <KeyValuePair <string, PathType> > CompileListWithCurrent(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { var last = CompileCurrent(context, index, out errProducer); if (last == null) { return(PathParts.GetList()); } if (!(PathParts.Many && last.Value.Value == PathType.SelfAssignment)) { PathParts.Add(last.Value.Key, last.Value.Value); } return(PathParts.GetList()); }
public IList <KeyValuePair <string, PathType> > Compile(TokenzierContext context, int index) { return(PathParts.GetList()); }
private bool ComputeCurrentPart(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { errProducer = null; var checkPathPart = CheckPathPart(); if (checkPathPart != -1) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, checkPathPart, CurrentPart)), CurrentPart)); return(false); } if (CurrentPart == "null") { if (PathParts.Any) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An null must be at the start of an expression")); return(false); } PathParts.Add(null, PathType.Null); return(true); } if (CurrentPart == "true" || CurrentPart == "false") { if (PathParts.Any) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An boolean must be at the start of an expression")); return(false); } PathParts.Add(CurrentPart, PathType.Boolean); return(true); } if (CurrentPart == "../") { PathParts.Add(null, PathType.ParentSelector); return(true); } if (CurrentPart == "~") { PathParts.Add(null, PathType.RootSelector); return(true); } if (CurrentPart == "?") { PathParts.Add(null, PathType.ObjectSelector); return(true); } PathParts.Add(CurrentPart, PathType.DataPath); return(true); }
public bool Add(char c, TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { errProducer = null; if (!Tokenizer.IsExpressionPathChar(c)) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart); return(false); } if (PathParts.IsNullValue) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Nothing can follow on a null"); return(false); } LastCharWasDelimiter = c == '.'; if (c == '/') { if (CurrentPart == "..") { if (PathParts.Any && !PathParts.HasParentSelector) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An Parent selector '..\\' can only follow on another parent selector like and never on an root or an data selector"); return(false); } PathParts.Add(null, PathType.ParentSelector); CurrentPart = string.Empty; return(true); } errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Unexpected '/'. Expected ether the start of an expression or an './'"); return(false); } if (c == '~') { if (CurrentPart != string.Empty || PathParts.Any) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An root selector '~' must be at the start of an expression"); return(false); } PathParts.Add(null, PathType.RootSelector); CurrentPart = string.Empty; return(true); } if (c == '?') { PathParts.Add(null, PathType.ObjectSelector); CurrentPart = string.Empty; return(true); } if (c != '.' && CurrentPart == "." && !PathParts.Any) { //in this case somebody wrote .data //so ignore the dot CurrentPart = string.Empty; } if (CurrentPart != string.Empty && CurrentPart != "." && c == '.') { if (!ComputeCurrentPart(context, index, out errProducer)) { return(false); } CurrentPart = ""; } else { CurrentPart += c; } return(true); }