Exemplo n.º 1
0
		public void MultiLineTokens()
		{
			ScannerSpecification oSpec = new ScannerSpecification();
			oSpec.AddLiteral("l", CharType.Letters, '_');
			oSpec.AddLiteral("d", CharType.Numbers);
			oSpec.AddLiteral("br1", '[');
			oSpec.AddLiteral("br2", ']');

			oSpec.AddTokenDeclaration("id", "l{l|d}");
			oSpec.AddBoundedToken("id2", "br1", "br2", null);


			StateParser oStateParser = new StateParser(new StateScanner(oSpec, 4));
			oStateParser.Spec.AddRule("id", "id|id2");

			{
				oStateParser.SetSource(
@"select [
 x int] from x
");
				this.ReadAndAssertToken(oStateParser, "id", "select");
				this.ReadAndAssertToken(oStateParser, "id2", "[");
				this.ReadAndAssertToken(oStateParser, "id2", " x int]");
			}
		}
Exemplo n.º 2
0
		public void VariablesAssignment()
		{
			ScannerSpecification oSpec = new ScannerSpecification();
			oSpec.AddLiteral("l", CharType.Letters, '_');
			oSpec.AddLiteral("d", CharType.Numbers);
			oSpec.AddLiteral("x", '=', ';');

			oSpec.AddTokenDeclaration("id", "l{l|d}");
			oSpec.AddTokenDeclaration("number", "d{d}");
			oSpec.AddTokenDeclaration("sep", "x");

			StateParser oStateParser = new StateParser(new StateScanner(oSpec, 4));
			oStateParser.Spec.AddRule("Tag", "id sep number sep");

			{
				oStateParser.SetSource("sText=10;");
				this.ReadAndAssertToken(oStateParser, "id", "sText");
				this.ReadAndAssertToken(oStateParser, "sep", "=");
				this.ReadAndAssertToken(oStateParser, "number", "10");
				this.ReadAndAssertToken(oStateParser, "sep", ";");
				var oToken = oStateParser.GetNextToken();
				Assert.IsNull(oToken);
			}
		}