Skip to content

Commit

Permalink
Rename ReadArgument/ReadArgumentGroup back to ReadElement (ForNeVeR#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jan 3, 2020
1 parent d02e93a commit 67a882d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/WpfMath/Parsers/Matrices/MatrixCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/WpfMath/Parsers/StandardCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
47 changes: 25 additions & 22 deletions src/WpfMath/TexFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 + "'!");
Expand Down Expand Up @@ -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);
}

/// <summary>Reads an argument: typically, a curly brace-enclosed value group, a singular value or an escaped sequence of letters/a character.</summary>
/// <summary>
/// Reads an element: typically, a curly brace-enclosed value group, a singular value or a character sequence
/// prefixed by a backslash.
/// </summary>
/// <exception cref="TexParseException">Will be thrown for ill-formed groups.</exception>
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++;
Expand Down Expand Up @@ -394,25 +397,25 @@ 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(
TexFormula formula,
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());

/// <remarks>May return <c>null</c> for commands that produce no atoms.</remarks>
private Atom ProcessCommand(
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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());

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 67a882d

Please # to comment.