Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected fields | Protected static fields | List of all members
Loyc.Syntax.Les.Les2PrecedenceMap Class Reference

This class's main job is to maintain a table of Precedence values for LES operators. When you ask about a new operator, its precedence is chosen by this class and cached for future reference. More...


Source file:
Inheritance diagram for Loyc.Syntax.Les.Les2PrecedenceMap:
Loyc.Syntax.Les.Les3PrecedenceMap

Remarks

This class's main job is to maintain a table of Precedence values for LES operators. When you ask about a new operator, its precedence is chosen by this class and cached for future reference.

Properties

static Les2PrecedenceMap?? Default [get]
 
Pair< MMap< object, Precedence >, Precedencethis[OperatorShape s] [get, set]
 

Public Member Functions

virtual void Reset ()
 Forgets previously encountered operators to save memory. More...
 
Precedence Find (OperatorShape shape, object op, bool cacheWordOp=true)
 Gets the precedence in LES of a prefix, suffix, or infix operator. More...
 
Symbol ToSuffixOpName (object symbol)
 Given a normal operator symbol like (Symbol)"'++", gets the suffix form of the name, such as (Symbol)"'suf++". More...
 

Static Public Member Functions

static bool IsOpChar (char c)
 Returns true if this character is one of those that operators are normally made out of in LES. More...
 
static bool IsOpCharEx (char c)
 Returns true if this character is one of those that can appear in "extended" LESv3 operators that start with an apostrophe. More...
 
static bool IsNaturalOperator (UString name)
 Returns true if the given Symbol can be printed as an operator without escaping it in LESv2. More...
 
static bool IsNaturalOperatorToken (UString name)
 Like IsNaturalOperator, but doesn't expect name[0] is apostrophe. More...
 
static bool IsExtendedOperatorToken (UString name)
 Returns true if the given Symbol can ever be used as an "extended" binary operator in LESv3. More...
 
static bool ResemblesSuffixOperator (Symbol name, out Symbol bareName)
 Decides whether the name resembles a suffix operator. More...
 

Protected Member Functions

Precedence FindPrecedence (MMap< object, Precedence > table, object symbol, Precedence @default, bool cacheWordOp)
 

Protected fields

Pair< MMap< object, Precedence >, Precedence >[] _precedenceMap = new Pair<MMap<object, Precedence>, Precedence>[4]
 

Protected static fields

static Les2PrecedenceMap _default
 
static readonly Map< object, PrecedencePredefinedPrefixPrecedence
 
static readonly Map< object, PrecedencePredefinedSuffixPrecedence
 
static readonly Map< object, PrecedencePredefinedInfixPrecedence
 

Member Function Documentation

◆ Find()

Precedence Loyc.Syntax.Les.Les2PrecedenceMap.Find ( OperatorShape  shape,
object  op,
bool  cacheWordOp = true 
)
inline

Gets the precedence in LES of a prefix, suffix, or infix operator.

Parameters
shapeSpecifies which precedence table and rules to use (Prefix, Suffix or Infix). Note: when this is Suffix, "_" is not expected to be part of the name in op, i.e. op should be a Symbol like "'++" rather than "'_++" (see also ResemblesSuffixOperator)
opParsed form of the operator. op must be a Symbol, but the parameter has type object to avoid casting Token.Value in the parser.

◆ IsExtendedOperatorToken()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.IsExtendedOperatorToken ( UString  name)
inlinestatic

Returns true if the given Symbol can ever be used as an "extended" binary operator in LESv3.

A binary operator's length must be between 2 and 255, its name must start with an apostrophe, and each remaining character must be punctuation marks from natural operators and/or characters from the set {'#', '_', 'a'..'z', 'A'..'Z', '0'..'9', '$'}.

◆ IsNaturalOperator()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.IsNaturalOperator ( UString  name)
inlinestatic

Returns true if the given Symbol can be printed as an operator without escaping it in LESv2.

The parser should read something like +/* as an operator with three characters, rather than "+" and a comment, but the printer is more conservative, so this function returns false in such a case.

References Loyc.Syntax.Les.Les2PrecedenceMap.IsNaturalOperatorToken(), Loyc.UString.Length, and Loyc.UString.Slice().

◆ IsNaturalOperatorToken()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.IsNaturalOperatorToken ( UString  name)
inlinestatic

Like IsNaturalOperator, but doesn't expect name[0] is apostrophe.

References Loyc.UString.Length, and Loyc.UString.Slice().

Referenced by Loyc.Syntax.Les.Les2PrecedenceMap.IsNaturalOperator().

◆ IsOpChar()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.IsOpChar ( char  c)
inlinestatic

Returns true if this character is one of those that operators are normally made out of in LES.

◆ IsOpCharEx()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.IsOpCharEx ( char  c)
inlinestatic

Returns true if this character is one of those that can appear in "extended" LESv3 operators that start with an apostrophe.

◆ ResemblesSuffixOperator()

static bool Loyc.Syntax.Les.Les2PrecedenceMap.ResemblesSuffixOperator ( Symbol  name,
out Symbol  bareName 
)
inlinestatic

Decides whether the name resembles a suffix operator.

Parameters
namePotential operator name to evaluate.
bareNameIf the name begins with "'suf", this is the same name with "suf" removed, otherwise it is set to name itself. This output is calculated even if the function returns false.

This method doesn't verify that the operator IS a legal suffix operator, just that it has the form of one.

References Loyc.Symbol.Name.

◆ Reset()

virtual void Loyc.Syntax.Les.Les2PrecedenceMap.Reset ( )
inlinevirtual

Forgets previously encountered operators to save memory.

Reimplemented in Loyc.Syntax.Les.Les3PrecedenceMap.

◆ ToSuffixOpName()

Symbol Loyc.Syntax.Les.Les2PrecedenceMap.ToSuffixOpName ( object  symbol)
inline

Given a normal operator symbol like (Symbol)"'++", gets the suffix form of the name, such as (Symbol)"'suf++".

op must be a Symbol, but the parameter has type object to avoid casting Token.Value in the parser.

Member Data Documentation

◆ PredefinedPrefixPrecedence

readonly Map<object, Precedence> Loyc.Syntax.Les.Les2PrecedenceMap.PredefinedPrefixPrecedence
staticprotected
Initial value:
=
new MMap<object, Precedence>() {
{ S.Substitute, P.Substitute },
{ S.Dot, P.Substitute },
{ S.Colon, P.Substitute },
{ S.NotBits, P.Prefix },
{ S.Not, P.Prefix },
{ S.XorBits, P.Prefix },
{ S._AddressOf, P.Prefix },
{ S._Dereference,P.Prefix },
{ S._UnaryPlus, P.Prefix },
{ S._Negate, P.Prefix },
{ S.Mod, P.Prefix },
{ S.Div, P.Prefix },
{ S.DotDot, P.RangePrefix },
{ (Symbol)"'.<", P.RangePrefix },
{ (Symbol)"'~>", P.SquigglyPrefix },
{ (Symbol)"'<~", P.SquigglyPrefix },
{ (Symbol)"'->", P.ArrowPrefix },
{ (Symbol)"'<-", P.ArrowPrefix },
{ (Symbol)"':>", P.ColonArrowPrefix },
{ (Symbol)"'<:", P.ColonArrowPrefix },
{ (Symbol)"'?>", P.ColonArrowPrefix },
{ (Symbol)"'<?", P.ColonArrowPrefix },
{ S.GT, P.LambdaPrefix },
{ (Symbol)"'|>", P.TrianglePrefix },
{ (Symbol)"'<|", P.TrianglePrefix },
}.AsImmutable()

◆ PredefinedSuffixPrecedence

readonly Map<object, Precedence> Loyc.Syntax.Les.Les2PrecedenceMap.PredefinedSuffixPrecedence
staticprotected
Initial value:
=
new MMap<object, Precedence>() {
{ S.PreInc, P.Primary },
{ S.PreDec, P.Primary },
{ S.PreBangBang,P.Primary },
}.AsImmutable()