Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected static fields | List of all members
Loyc.Syntax.Les.LesPrecedenceMap 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 cached for future reference. More...


Source file:

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 cached for future reference.

Properties

static LesPrecedenceMap Default [get]
 

Public Member Functions

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 (string name)
 Returns true if the given Symbol can be printed as an operator without escaping it (LESv2) or adding an apostrophe on the front (LESv3). More...
 
static bool IsExtendedOperator (string name, string expectPrefix="'")
 Returns true if the given Symbol can ever be used as an "extended" binary operator in LESv3. More...
 
static bool IsSuffixOperatorName (Symbol name, out Symbol bareName, bool checkNatural)
 Decides whether the name appears to represent a suffix operator of the form sufOP or OP</c>. More...
 

Protected Member Functions

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

Protected static fields

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

Member Function Documentation

Precedence Loyc.Syntax.Les.LesPrecedenceMap.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, "suf" must not be part of the name in op (see IsSuffixOperatorName)
opParsed form of the operator. op must be a Symbol, but the parameter has type object to avoid casting Token.Value in the parser.
static bool Loyc.Syntax.Les.LesPrecedenceMap.IsExtendedOperator ( string  name,
string  expectPrefix = "'" 
)
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', '$'}.

static bool Loyc.Syntax.Les.LesPrecedenceMap.IsNaturalOperator ( string  name)
inlinestatic

Returns true if the given Symbol can be printed as an operator without escaping it (LESv2) or adding an apostrophe on the front (LESv3).

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.

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

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

static bool Loyc.Syntax.Les.LesPrecedenceMap.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.

static bool Loyc.Syntax.Les.LesPrecedenceMap.IsSuffixOperatorName ( Symbol  name,
out Symbol  bareName,
bool  checkNatural 
)
inlinestatic

Decides whether the name appears to represent a suffix operator of the form sufOP or OP</c>.

Parameters
namePotential operator name to evaluate.
bareNameIf the name ends with "suf", this is the same name without "suf", otherwise it is set to name itself. This output is calculated even if the function returns false.
checkNaturalIf true, part of the requirement for returning true will be that IsNaturalOperator(bareName) == true.

References Loyc.Symbol.Name.

void Loyc.Syntax.Les.LesPrecedenceMap.Reset ( )
inline

Forgets previously encountered operators to save memory.

Symbol Loyc.Syntax.Les.LesPrecedenceMap.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

readonly Map<object, Precedence> Loyc.Syntax.Les.LesPrecedenceMap.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.Mod, P.Prefix },
{ S.XorBits, P.Prefix },
{ S._AddressOf, P.Prefix },
{ S._Dereference,P.Prefix },
{ S._UnaryPlus, P.Prefix },
{ S._Negate, P.Prefix },
{ S.DotDot, P.PrefixDots },
{ S.OrBits, P.PrefixOr },
{ S.Div, P.Prefix },
}.AsImmutable()
readonly Map<object, Precedence> Loyc.Syntax.Les.LesPrecedenceMap.PredefinedSuffixPrecedence
staticprotected
Initial value:
=
new MMap<object, Precedence>() {
{ S.PreInc, P.Primary },
{ S.PreDec, P.Primary },
}.AsImmutable()