private void ValidateNoUndeclaredCharsets(CharsetExpression expr) { if (expr is CharsetBinaryExpression) { var b = expr as CharsetBinaryExpression; ValidateNoUndeclaredCharsets(b.Left); ValidateNoUndeclaredCharsets(b.Right); } else if (expr is CharsetNameExpression) { var b = expr as CharsetNameExpression; if (!IsReservedCharsetName(b.Name) && !CharsetDefinitions.Any(x => x.Name == b.Name)) { throw new GrammarException(b.Location, $"nome {{{b.Name}}} não declarado"); } } }
private void ValidateNoRecursionCharset(CharsetExpression r, HashSet <string> stack) { if (r is CharsetNameExpression) { var rr = r as CharsetNameExpression; if (stack.Contains(rr.Name)) { throw new GrammarException(r.Location, $"recursão infinita para {{{rr.Name}}}"); } stack.Add(rr.Name); if (IsReservedCharsetName(rr.Name)) { return; } ValidateNoRecursionCharset(CharsetDefinitions.First(x => x.Name == rr.Name).Expression, stack); } else if (r is CharsetBinaryExpression) { var b = r as CharsetBinaryExpression; ValidateNoRecursionCharset(b.Left, stack); ValidateNoRecursionCharset(b.Right, stack); } }
public CharsetBinaryExpression(CharsetBinaryOperator @operator, CharsetExpression left, CharsetExpression right, Location location) : base(location) { Operator = @operator; Left = left; Right = right; }
public CharsetDefinition(string name, CharsetExpression expression, Location location) { Name = name; Expression = expression; Location = location; }