using System.Diagnostics;
using System.Runtime.InteropServices;
namespace LLama.Native
{
///
/// grammar element type
///
public enum LLamaGrammarElementType
{
///
/// end of rule definition
///
END = 0,
///
/// start of alternate definition for rule
///
ALT = 1,
///
/// non-terminal element: reference to rule
///
RULE_REF = 2,
///
/// terminal element: character (code point)
///
CHAR = 3,
///
/// inverse char(s) ([^a], [^a-b] [^abc])
///
CHAR_NOT = 4,
///
/// modifies a preceding CHAR or CHAR_ALT to
/// be an inclusive range ([a-z])
///
CHAR_RNG_UPPER = 5,
///
/// modifies a preceding CHAR or
/// CHAR_RNG_UPPER to add an alternate char to match ([ab], [a-zA])
///
CHAR_ALT = 6,
}
///
/// An element of a grammar
///
[StructLayout(LayoutKind.Sequential)]
[DebuggerDisplay("{Type} {Value}")]
public record struct LLamaGrammarElement
{
///
/// The type of this element
///
public LLamaGrammarElementType Type;
///
/// Unicode code point or rule ID
///
public uint Value;
///
/// Construct a new LLamaGrammarElement
///
///
///
public LLamaGrammarElement(LLamaGrammarElementType type, uint value)
{
Type = type;
Value = value;
}
internal bool IsCharElement()
{
switch (Type)
{
case LLamaGrammarElementType.CHAR:
case LLamaGrammarElementType.CHAR_NOT:
case LLamaGrammarElementType.CHAR_ALT:
case LLamaGrammarElementType.CHAR_RNG_UPPER:
return true;
default:
return false;
}
}
}
}