Example #1
0
 public IdentifierNode(IdentifierNode node)
 {
     Name = node.Name;
       AtmarkPrefix = node.AtmarkPrefix;
       ExpressionPrefix = node.ExpressionPrefix;
       TypePrefix = node.TypePrefix;
 }
Example #2
0
 /// <summary>
 /// Throw an error message bound to some other lexem
 /// </summary>
 /// <param name="msg">Error message</param>
 /// <param name="lexem">Lexem</param>
 public void Error(string msg, Lexem lexem)
 {
     throw new CompilerException(msg, lexem);
 }
Example #3
0
 public IdentifierNode(string name, string typePrefix)
 {
     Name = name;
       TypePrefix = new Lexer.Lexem(Lexer.LexemType.Identifier, typePrefix);
 }
Example #4
0
        /// <summary>
        /// Try to find a static lexem at current position
        /// </summary>
        /// <param name="str">String</param>
        /// <param name="offset">Offset inside string</param>
        /// <returns></returns>
        private Lexem ExtractStaticLexem(string str, int offset)
        {
            foreach (var curr in StaticLexems)
              {
            // looks like we got a complete match
            if (str.SafeSubstring(offset, curr.Signature.Length) == curr.Signature)
            {
              // if this was only a part of the identifier - false alarm
              if (curr.IsIdentifier && IsPartOfIdentifier(str, offset + curr.Signature.Length))
            continue;

              var lexem = new Lexem(curr.Type);
              lexem.Length = curr.Signature.Length;
              return lexem;
            }
              }

              return null;
        }
Example #5
0
        /// <summary>
        /// Try to find a dynamic lexem at current position
        /// </summary>
        /// <param name="str">String</param>
        /// <param name="offset">Offset inside string</param>
        /// <returns></returns>
        private Lexem ExtractDynamicLexem(string str, int offset)
        {
            var piece = str.Substring(offset, str.Length - offset);
              foreach (var curr in DynamicLexems)
              {
            // perform a regex match
            var match = curr.Signature.Match(piece);
            if (match.Success)
            {
              var lexem = new Lexem(curr.Type, match.Value);

              // special case of string regexp
              if (curr.Type == LexemType.StringLiteral)
            lexem.Data = lexem.Data.SafeSubstring(1, lexem.Data.Length - 2);
              lexem.Length = match.Value.Length;

              return lexem;
            }
              }

              return null;
        }
Example #6
0
 /// <summary>
 /// Create an exception based on a lexem
 /// </summary>
 /// <param name="msg">Message</param>
 /// <param name="lexem">Erroneous lexem</param>
 public CompilerException(string msg, Lexem lexem)
     : base(msg)
 {
     if(lexem != null)
     AffixToLexem(lexem);
 }
Example #7
0
        /// <summary>
        /// Set exception properties based on a lexem
        /// </summary>
        /// <param name="lexem">Lexem to affix to</param>
        public void AffixToLexem(Lexem lexem)
        {
            // already affixed
              if (Affixed) return;

              Line = lexem.Line;
              Offset = lexem.Offset;
              Position = lexem.TotalOffset;
              File = lexem.File;
              Length = lexem.Length;

              Affixed = true;
        }