From 67a882dcec553dd0d084312ca7a4f6cb79a8ca85 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Fri, 3 Jan 2020 16:18:51 +0700 Subject: [PATCH] Rename ReadArgument/ReadArgumentGroup back to ReadElement (#59) --- .../Parsers/Matrices/MatrixCommandParser.cs | 2 +- src/WpfMath/Parsers/StandardCommands.cs | 6 +-- src/WpfMath/TexFormulaParser.cs | 47 ++++++++++--------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/WpfMath/Parsers/Matrices/MatrixCommandParser.cs b/src/WpfMath/Parsers/Matrices/MatrixCommandParser.cs index 7b0e7883..00ac207b 100644 --- a/src/WpfMath/Parsers/Matrices/MatrixCommandParser.cs +++ b/src/WpfMath/Parsers/Matrices/MatrixCommandParser.cs @@ -30,7 +30,7 @@ public CommandProcessingResult ProcessCommand(CommandContext context) if (position == source.Length) throw new TexParseException("illegal end!"); - var cellsSource = TexFormulaParser.ReadArgument(source, ref position); + var cellsSource = TexFormulaParser.ReadElement(source, ref position); var matrixSource = context.CommandSource.Segment( context.CommandNameStartPosition, position - context.CommandNameStartPosition); diff --git a/src/WpfMath/Parsers/StandardCommands.cs b/src/WpfMath/Parsers/StandardCommands.cs index fe2daede..546ef2e1 100644 --- a/src/WpfMath/Parsers/StandardCommands.cs +++ b/src/WpfMath/Parsers/StandardCommands.cs @@ -13,7 +13,7 @@ public CommandProcessingResult ProcessCommand(CommandContext context) var source = context.CommandSource; var position = context.ArgumentsStartPosition; var underlineFormula = context.Parser.Parse( - TexFormulaParser.ReadArgument(source, ref position), + TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment); var start = context.CommandNameStartPosition; @@ -30,11 +30,11 @@ public CommandProcessingResult ProcessCommand(CommandContext context) var source = context.CommandSource; var position = context.ArgumentsStartPosition; var topFormula = context.Parser.Parse( - TexFormulaParser.ReadArgument(source, ref position), + TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment.CreateChildEnvironment()); var bottomFormula = context.Parser.Parse( - TexFormulaParser.ReadArgument(source, ref position), + TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment.CreateChildEnvironment()); var start = context.CommandNameStartPosition; diff --git a/src/WpfMath/TexFormulaParser.cs b/src/WpfMath/TexFormulaParser.cs index f2376e2c..e21ae723 100644 --- a/src/WpfMath/TexFormulaParser.cs +++ b/src/WpfMath/TexFormulaParser.cs @@ -253,7 +253,7 @@ private TexFormula Parse( } else if (ch == leftGroupChar) { - var groupValue = ReadArgument(value, ref position); + var groupValue = ReadElement(value, ref position); var parsedGroup = Parse(groupValue, textStyle, environment.CreateChildEnvironment()); var innerGroupAtom = parsedGroup.RootAtom ?? new RowAtom(groupValue); var groupAtom = new TypedAtom( @@ -318,7 +318,7 @@ private static TexFormula ConvertRawText(SourceSpan value, string textStyle) return formula; } - internal static SourceSpan ReadArgumentGroup(SourceSpan value, ref int position, char openChar, char closeChar) + internal static SourceSpan ReadElementGroup(SourceSpan value, ref int position, char openChar, char closeChar) { if (position == value.Length || value[position] != openChar) throw new TexParseException("missing '" + openChar + "'!"); @@ -356,17 +356,20 @@ private static SourceSpan ReadElementGroupOptional( if (value[position] != openChar) return null; - return ReadArgumentGroup(value, ref position, openChar, closeChar); + return ReadElementGroup(value, ref position, openChar, closeChar); } - /// Reads an argument: typically, a curly brace-enclosed value group, a singular value or an escaped sequence of letters/a character. + /// + /// Reads an element: typically, a curly brace-enclosed value group, a singular value or a character sequence + /// prefixed by a backslash. + /// /// Will be thrown for ill-formed groups. - internal static SourceSpan ReadArgument(SourceSpan value, ref int position) + internal static SourceSpan ReadElement(SourceSpan value, ref int position) { if (position < value.Length) { if (value[position] == leftGroupChar) - return ReadArgumentGroup(value, ref position, leftGroupChar, rightGroupChar); + return ReadElementGroup(value, ref position, leftGroupChar, rightGroupChar); else if (value[position] == escapeChar) { position++; @@ -394,17 +397,17 @@ internal static SourceSpan ReadArgument(SourceSpan value, ref int position) if (elementfound) return value.Segment(start-1, position - start+1); else - throw new TexParseException("An argument is missing"); + throw new TexParseException("An element is missing"); } } else - throw new TexParseException("An argument is missing"); + throw new TexParseException("An element is missing"); } else return value.Segment(position++, 1); } else - throw new TexParseException("An argument is missing"); + throw new TexParseException("An element is missing"); } private TexFormula ReadScript( @@ -412,7 +415,7 @@ private TexFormula ReadScript( SourceSpan value, ref int position, ICommandEnvironment environment) => - Parse(ReadArgument(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); + Parse(ReadElement(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); /// May return null for commands that produce no atoms. private Atom ProcessCommand( @@ -432,11 +435,11 @@ private Atom ProcessCommand( case "frac": { var numeratorFormula = Parse( - ReadArgument(value, ref position), + ReadElement(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); var denominatorFormula = Parse( - ReadArgument(value, ref position), + ReadElement(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); source = value.Segment(start, position - start); @@ -448,7 +451,7 @@ private Atom ProcessCommand( if (position == value.Length) throw new TexParseException("`left` command should be passed a delimiter"); - string delimiter = ReadArgument(value, ref position).ToString().Trim(); + string delimiter = ReadElement(value, ref position).ToString().Trim(); var left = position; @@ -476,7 +479,7 @@ private Atom ProcessCommand( case "overline": { var overlineFormula = Parse( - ReadArgument(value, ref position), + ReadElement(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); source = value.Segment(start, position - start); @@ -491,7 +494,7 @@ private Atom ProcessCommand( if (position == value.Length) throw new TexParseException("`right` command should be passed a delimiter"); - string delimiter = ReadArgument(value, ref position).ToString().Trim(); + string delimiter = ReadElement(value, ref position).ToString().Trim(); SymbolAtom closing = null; if (delimiter.Length == 1) @@ -521,13 +524,13 @@ private Atom ProcessCommand( { // Degree of radical is specified. degreeFormula = Parse( - ReadArgumentGroup(value, ref position, leftBracketChar, rightBracketChar), + ReadElementGroup(value, ref position, leftBracketChar, rightBracketChar), formula.TextStyle, environment.CreateChildEnvironment()); } var sqrtFormula = this.Parse( - ReadArgument(value, ref position), + ReadElement(value, ref position), formula.TextStyle, environment.CreateChildEnvironment()); @@ -538,7 +541,7 @@ private Atom ProcessCommand( { var color = ReadColorModelData(value, ref position); - var bodyValue = ReadArgument(value, ref position); + var bodyValue = ReadElement(value, ref position); var bodyFormula = Parse(bodyValue, formula.TextStyle, environment.CreateChildEnvironment()); source = value.Segment(start, position - start); @@ -548,7 +551,7 @@ private Atom ProcessCommand( { var color = ReadColorModelData(value, ref position); - var bodyValue = ReadArgument(value, ref position); + var bodyValue = ReadElement(value, ref position); var bodyFormula = Parse(bodyValue, formula.TextStyle, environment.CreateChildEnvironment()); source = value.Segment(start, position - start); @@ -582,7 +585,7 @@ private Color ReadColorModelData(SourceSpan value, ref int position) ref position, leftBracketChar, rightBracketChar)?.ToString(); - var colorDefinition = ReadArgument(value, ref position).ToString(); + var colorDefinition = ReadElement(value, ref position).ToString(); var colorComponents = colorDefinition.Split(',').Select(c => c.Trim()); var colorParser = string.IsNullOrEmpty(colorModelName) @@ -672,8 +675,8 @@ private void ProcessEscapeSequence(TexFormula formula, SkipWhiteSpace(value, ref position); var styledFormula = command == TexUtilities.TextStyleName - ? ConvertRawText(ReadArgument(value, ref position), command) - : Parse(ReadArgument(value, ref position), command, environment.CreateChildEnvironment()); + ? ConvertRawText(ReadElement(value, ref position), command) + : Parse(ReadElement(value, ref position), command, environment.CreateChildEnvironment()); var source = value.Segment(start, position - start); var atom = styledFormula.RootAtom ?? new NullAtom(source);