Home > ASP.NET MVC > ASP.NET MVC: Razor’s Parsing Algorithm for Code Nuggets

ASP.NET MVC: Razor’s Parsing Algorithm for Code Nuggets

In ASP.NET MVC , there is view engine called Razor that is very easy compared to ASPX view engine . it allow you to code within aspx html fully utilizing your C# and VB.net skill , more details of its uses syntax. you can follow this link of Scott Guthrie  http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx

The below algorithm captures the core parsing logic we use to support “@” expressions within Razor, and to enable the implicit code nugget scenarios above:

  1. Parse an identifier – As soon as we see a character that isn’t valid in a C# or VB identifier, we stop and move to step 2
  2. Check for brackets – If we see “(” or “[“, go to step 2.1., otherwise, go to step 3
    1. Parse until the matching “)” or “]” (we track nested “()” and “[]” pairs and ignore “()[]” we see in strings or comments)
    2. Go back to step 2
  3. Check for a “.” – If we see one, go to step 3.1, otherwise, DO NOT ACCEPT THE “.” as code, and go to step 4
    1. If the character AFTER the “.” is a valid identifier, accept the “.” and go back to step 1, otherwise, go to step 4
  4. Done!
Categories: ASP.NET MVC Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: