public override void Visit(Module pair) { PrintNodeName(pair); PrintNodeStart(pair); base.Visit(pair); PrintNodeEnd(pair); }
private string VerifyScopeName(string name, Interval nameInterval, Module module) { if (string.IsNullOrEmpty(name)) { return(name); } return(VerifyNsName(name, nameInterval, module)); }
private string VerifyNsName(string name, Interval nameInterval, Module module) { if (Regex.Match(name, @"^[a-zA-Z_][a-zA-Z0-9_\-]*$").Success) { return(name); } _context.Errors.Add(CompilerErrorFactory.InvalidNsName(nameInterval, module.FileName)); return(name); }
/// <summary> /// Creates instance of the <see cref="Parser"/>. /// </summary> /// <param name="input">Stream of characters for parsing.</param> /// <param name="pairFactory">Pair factory is used to create DOM structure of the Syntactik document.</param> /// <param name="root"><see cref="DOM.Module"/> object is used as root of DOM structure.</param> /// <param name="processJsonBrackets">If true, parser will process {} and [] brackets.</param> public Parser(ICharStream input, IPairFactory pairFactory, DOM.Module root, bool processJsonBrackets = false) { _input = input; _pairFactory = pairFactory; _pairStack = new Stack <PairIndentInfo>(); _pairStack.Push(new PairIndentInfo { Pair = root }); _module = root; _processJsonBrackets = processJsonBrackets; }
private string VerifyName(string name, Interval nameInterval, Module module) { try { XmlConvert.VerifyNCName(name); } catch (Exception) { _context.Errors.Add(CompilerErrorFactory.InvalidName(nameInterval, module.FileName)); } return(name); }
private string VerifyElementName(string name, Interval nameInterval, Module module) { if (string.IsNullOrEmpty(name)) { return(name); } try { XmlConvert.VerifyNCName(name); } catch (XmlException) { _context.Errors.Add(CompilerErrorFactory.InvalidXmlElementName(nameInterval, module.FileName)); } return(name); }
private static Alias GetAliasInterpolationItem(Match match, int line, int column, CompilerContext context, Module module) { if (match.Value.StartsWith(@"\$(") && !match.Value.EndsWith(@")")) { context.Errors.Add(CompilerErrorFactory.ParserError("Missing closing parenthesis.", module.FileName, line, column + match.Length)); } var alias = new Alias ( name: match.Value.TrimStart('\\', '$', '(', '\t', ' ').TrimEnd(')', '\t', ' '), nameInterval: new Interval(new CharLocation(line, column, -1), new CharLocation(line, column + match.Value.Length, -1)), assignment: AssignmentEnum.None, value: null, valueType: ValueType.Empty, isValueNode: true ); return(alias); }
private static EscapeMatch GetEscapeInterpolationItem(Match match, int line, int column, CompilerContext context, Module module) { var escape = match.Value; if (escape.Length < 2) { context.Errors.Add(CompilerErrorFactory.ParserError("Invalid escape sequence.", module.FileName, line, column)); } else { switch (escape[1]) { //'b'|'f'|'n'|'r'|'t'|'v' case '"': case '\\': case '/': case 'b': case 'f': case 'n': case 'r': case 't': case 'v': break; case 'u': if (match.Length < 6) { context.Errors.Add(CompilerErrorFactory.ParserError("Invalid escape sequence.", module.FileName, line, column)); } break; default: context.Errors.Add(CompilerErrorFactory.ParserError("Invalid escape sequence.", module.FileName, line, column)); break; } } return(new EscapeMatch { Value = match.Value }); }
/// <summary> /// Creates instance of <see cref="PairFactoryForXml"/>. /// </summary> /// <param name="context"><see cref="CompilerContext"/> used to report errors.</param> /// <param name="module">Current module.</param> public PairFactoryForXml(CompilerContext context, Module module) { _context = context; _module = module; }
internal static List <object> GetInterpolationItems(ITextSource input, Interval valueInterval, CompilerContext context, Module module) { var intItems = new List <object>(); var i = ValueIsMissingQuote(input, '"', valueInterval) ? 0 : -1; var value = input.GetText(valueInterval.Begin.Index + 1, valueInterval.End.Index + i); var matches = Regex.Matches(value, //Escape characters @"(\\(?:[""\\\/bfnrt]|u[a-fA-F0-9]{0,4}|" + //Alias or parameter with brackets @"(?:\$|!%)\([ \t]*(?:(?:_|[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD])" + @"(?:[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" + @"-|\.|[0-9]|\xB7|[\u0300-\u036F]|[\u203F-\u2040])*)[ \t]*\)?|" + //Alias or parameter without brackets @"(?:\$|!%)(?:(?:_|[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD])" + @"(?:[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" + @"-|\.|[0-9]|\xB7|[\u0300-\u036F]|[\u203F-\u2040])*)" + //Incorrect escape, indent, new line, other characters @"|.?))|(\r?\n[ \t]*)|([^\\\0-\x1F\x7F]+)", RegexOptions.Singleline); var line = valueInterval.Begin.Line; var column = valueInterval.Begin.Column; foreach (var match in matches) { if (((Match)match).Value.StartsWith(@"\$")) { intItems.Add(GetAliasInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith(@"\!%")) { intItems.Add(GetParameterInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith(@"\")) { intItems.Add(GetEscapeInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith("\n") || ((Match)match).Value.StartsWith("\r")) { intItems.Add(GetEolEscapeInterpolationItem((Match)match)); } else { intItems.Add(((Match)match).Value); } if (((Match)match).Value.StartsWith("\n")) { line++; column = ((Match)match).Value.Length; } else if (((Match)match).Value.StartsWith("\r")) { line++; column = ((Match)match).Value.Length + 1; } else { column += ((Match)match).Value.Length; } } return(intItems); }
internal static Tuple <string, List <object> > GetValue(ITextSource input, AssignmentEnum assignment, int valueQuotesType, Interval valueInterval, int valueIndent, CompilerContext context, Module module) { if (valueInterval == null) { if (assignment == AssignmentEnum.E || assignment == AssignmentEnum.EE) { return(new Tuple <string, List <object> >(string.Empty, null)); } return(new Tuple <string, List <object> >(null, null)); } if (valueInterval.Begin.Index == -1) { return(new Tuple <string, List <object> >(string.Empty, null)); } if (valueQuotesType == '\'') { if (!ValueIsMissingQuote(input, valueQuotesType, valueInterval)) { return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index - 1, valueIndent), null)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index, valueIndent), null)); } if (valueQuotesType == '"') { var ii = GetInterpolationItems(input, valueInterval, context, module); string value = (string)(ii.Count == 1 && ii[0] is string?ii[0] : string.Empty); return(new Tuple <string, List <object> >(value, ii)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index, valueInterval.End.Index, valueIndent), null)); }
private static Parameter GetParameterInterpolationItem(Match match, int line, int column, CompilerContext context, Module module) { if (match.Value.StartsWith(@"\!%(") && !match.Value.EndsWith(@")")) { context.Errors.Add(CompilerErrorFactory.ParserError("Missing closing parenthesis.", module.FileName, line, column + match.Length)); } var parameter = new Parameter { Name = match.Value.TrimStart('\\', '!', '%', '(', '\t', ' ').TrimEnd(')', '\t', ' '), NameInterval = new Interval(new CharLocation(line, column, -1), new CharLocation(line, column + match.Value.Length, -1)), Delimiter = DelimiterEnum.None, ValueType = ValueType.Empty, IsValueNode = true }; return(parameter); }
internal static Tuple <string, List <object> > GetValue(ICharStream input, DOM.DelimiterEnum delimiter, int valueQuotesType, DOM.Interval valueInterval, int valueIndent, CompilerContext context, Module module) { if (valueInterval == null) { if (delimiter == DOM.DelimiterEnum.E || delimiter == DOM.DelimiterEnum.EE) { return(new Tuple <string, List <object> >(string.Empty, null)); } return(new Tuple <string, List <object> >(null, null)); } if (valueInterval.Begin.Index == -1) { return(new Tuple <string, List <object> >(string.Empty, null)); } if (valueQuotesType == (int)DOM.QuotesEnum.Single) { if (!ValueIsMissingQuote(input, valueQuotesType, valueInterval)) { return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index - 1, valueIndent), null)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index, valueIndent), null)); } if (valueQuotesType == (int)QuotesEnum.Double) { var ii = GetInterpolationItems((ITextSource)input, valueInterval, context, module); string value = (string)(ii.Count == 1 && ii[0] is string?ii[0] : string.Empty); return(new Tuple <string, List <object> >(value, ii)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index, valueInterval.End.Index, valueIndent), null)); }