Skip to content

Commit

Permalink
-Integrated Lua parser with Lua language service object
Browse files Browse the repository at this point in the history
-Fixed issue where comments were being passed to parser
-Lots of misc grammar production fixes
-Implemented code outlining
-Lexer bugfix on string literals
  • Loading branch information
Trystan Larey-Williams committed Sep 5, 2006
1 parent 9f7083b commit 2d33754
Show file tree
Hide file tree
Showing 12 changed files with 7,405 additions and 7,413 deletions.
Binary file modified LuaLangPack/LuaLangPack.suo
Binary file not shown.
1 change: 1 addition & 0 deletions LuaLangPack/LuaLangPack/LuaLangPack.csproj
Expand Up @@ -115,6 +115,7 @@
<Compile Include="LuaScanner.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="source.cs" />
<Compile Include="VSPackage.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
3 changes: 3 additions & 0 deletions LuaLangPack/LuaLangPack/LuaLangPack.csproj.user
Expand Up @@ -20,4 +20,7 @@
<StartArguments>/rootsuffix Exp</StartArguments>
<StartAction>Program</StartAction>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartArguments>/rootsuffix Exp /noVSIP</StartArguments>
</PropertyGroup>
</Project>
26 changes: 1 addition & 25 deletions LuaLangPack/LuaLangPack/LuaLangPack.wxs
Expand Up @@ -168,11 +168,6 @@
Name='LuaLan~1.dll'
src='./Release/LuaLangPack.dll' />

<File Id='NativeHierarchyWrapper'
LongName='Interop.NativeHierarchyWrapper.dll'
Name='Intero~1.dll'
src='./Release/Interop.NativeHierarchyWrapper.dll' />

<File Id='Tools.dll'
LongName='Tools.dll'
Name='Tools.dll'
Expand All @@ -182,11 +177,6 @@
LongName='logo.ico'
Name='logo.ico'
src='./Resources/logo.ico' />

<File Id="HierWrapper"
Name="NATIVE_1.DLL"
LongName="NativeHierarchyWrapper.dll"
src="d:\Program Files\Visual Studio 2005 SDK\2006.02\VisualStudioIntegration\Common\Source\CSharp\NativeHierarchyWrapper\Release\NativeHierarchyWrapper.dll" />

<Registry Id="registry0" Root="HKCR"
Key="CLSID\{A0E8320F-40D7-45d8-B94F-CA4C13141B56}"
Expand Down Expand Up @@ -218,21 +208,7 @@
<Registry Id="registry9" Root="HKCR"
Key="TypeLib\{9AA6D9FE-55CC-4a02-B6EF-0448C48B939D}\8.0\HELPDIR"
Value="[PRODDIR_2005]Lua" Type="string" />
<Registry Id="registry10" Root="HKCR" Key="VisualStudio.NativeHierarchyWrapper"
Value="VisualStudio NativeHierarchyWrapper" Type="string" />
<Registry Id="registry11" Root="HKCR"
Key="VisualStudio.NativeHierarchyWrapper\CLSID"
Value="{A0E8320F-40D7-45d8-B94F-CA4C13141B56}" Type="string" />
<Registry Id="registry12" Root="HKCR"
Key="VisualStudio.NativeHierarchyWrapper\CurVer"
Value="VisualStudio.NativeHierarchyWrapper.8.0" Type="string" />
<Registry Id="registry13" Root="HKCR"
Key="VisualStudio.NativeHierarchyWrapper.8.0"
Value="VisualStudio NativeHierarchyWrapper" Type="string" />
<Registry Id="registry14" Root="HKCR"
Key="VisualStudio.NativeHierarchyWrapper.8.0\CLSID"
Value="{A0E8320F-40D7-45d8-B94F-CA4C13141B56}" Type="string" />


<Registry Id='LuaReg1' Root='HKCR' Key='.lua' Action='write'
Type='string' Value='VisualStudio.lua.8.0' />
<Registry Id='LuaReg2' Root='HKCR' Key='VisualStudio.lua.8.0' Action='write'
Expand Down
59 changes: 29 additions & 30 deletions LuaLangPack/LuaLangPack/LuaLangService.cs
Expand Up @@ -21,7 +21,7 @@ public class LuaScope
{
public LuaScope( LuaScope parent ) {
m_parent = parent;
beginLine = 0; endLine = 0;
beginLine = -1; endLine = -1; beginIndx = -1; endIndx = -1;
}

// Searches through current and parent scopes for given table (Lua has lexical scoping)
Expand All @@ -38,16 +38,11 @@ public void AddRegions(AuthoringSink sink)
if (beginLine != endLine)
{
TextSpan span = new TextSpan();
NewHiddenRegion region = new NewHiddenRegion();
span.iStartLine = beginLine;
span.iEndLine = endLine;
span.iEndIndex = 0;
span.iStartIndex = 0;
region.dwBehavior = (uint)HIDDEN_REGION_BEHAVIOR.hrbEditorControlled;
region.dwState = (uint)HIDDEN_REGION_STATE.hrsExpanded;
region.iType = (int)HIDDEN_REGION_TYPE.hrtCollapsible;
region.tsHiddenText = span;
sink.AddHiddenRegion(region);
span.iStartLine = beginLine - 1;
span.iEndLine = endLine - 1;
span.iEndIndex = endIndx - 1;
span.iStartIndex = beginIndx;
sink.AddHiddenRegion(span);
}

foreach( LuaScope scope in nested )
Expand All @@ -58,6 +53,8 @@ public void AddRegions(AuthoringSink sink)

public int beginLine;
public int endLine;
public int beginIndx;
public int endIndx;
public LinkedList<LuaScope> nested = new LinkedList<LuaScope>();
public Hashtable tables = new Hashtable();

Expand All @@ -71,25 +68,21 @@ class LuaLangService : LanguageService
{
private LuaScanner m_scanner;
private LuaAuthScope m_authScope = new LuaAuthScope();
// private LuaSource m_source;
private LuaSource m_source;

// public override Source CreateSource(IVsTextLines buffer)
// {
// m_source = new LuaSource(this, buffer, GetColorizer(buffer));
// return (m_source);
// }
public override Source CreateSource(IVsTextLines buffer)
{
m_source = new LuaSource(this, buffer, GetColorizer(buffer));
return (m_source);
}

public override LanguagePreferences GetLanguagePreferences()
{
LanguagePreferences langPref = new LanguagePreferences();
langPref.EnableCodeSense = true;
langPref.EnableCommenting = false;
langPref.EnableFormatSelection = false;
langPref.EnableAsyncCompletion = true;
langPref.AutoOutlining = true;
langPref.EnableMatchBraces = false;
langPref.EnableMatchBracesAtCaret = false;
langPref.EnableQuickInfo = false;
langPref.MaxRegionTime = 1000000;
return langPref;
}

Expand All @@ -108,24 +101,30 @@ public override string Name

public override AuthoringScope ParseSource(ParseRequest req)
{
req.Sink.ProcessHiddenRegions = false;

if (req.Reason == ParseReason.DisplayMemberList)
{

}
else if (req.Reason == ParseReason.Check) // parse all code passed to us
{
LuaScope scope = new LuaScope( null );
Parser p = new syntax(new yysyntax());
Parser p = new syntax();
SYMBOL ast;
ast = p.Parse(req.Text);
if (ast.yyname == "chunk")

if (ast == null)
return m_authScope;

if (ast.yyname == "error")
{
Console.Write("Parse Error: " + ast.Pos);
}
else if (ast.yyname == "chunk")
{
chunk node = (chunk)ast;
node.FillScope(scope);
scope.AddRegions(req.Sink);
req.Sink.ProcessHiddenRegions = true;
chunk node = (chunk)ast;
node.FillScope(scope);
scope.AddRegions(req.Sink);
req.Sink.ProcessHiddenRegions = true;
}
}

Expand Down
49 changes: 33 additions & 16 deletions LuaLangPack/LuaLangPack/LuaScanner.cs
Expand Up @@ -15,6 +15,7 @@ class LuaScanner : IScanner

private Hashtable tokenInf = new Hashtable();
private Lexer lexer = new tokens();
private string srcBuf;

public LuaScanner()
{
Expand Down Expand Up @@ -86,33 +87,49 @@ public LuaScanner()

public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
{
TOKEN tok = lexer.Next();
if (tok == null)
return false;
// Handle comments as a special case. We don't tokenize them in the lexer
// since we don't want to send them to the parser.
int yypos = lexer.yypos;

if (tokenInf.Contains(tok.yyname))
TOKEN tok = lexer.Next();
if (tok != null)
{
TokenInfo inf = (TokenInfo)tokenInf[tok.yyname];
tokenInfo.Color = inf.Color;
tokenInfo.Type = inf.Type;
tokenInfo.Trigger = inf.Trigger;
if (tokenInf.Contains(tok.yyname))
{
TokenInfo inf = (TokenInfo)tokenInf[tok.yyname];
tokenInfo.Color = inf.Color;
tokenInfo.Type = inf.Type;
tokenInfo.Trigger = inf.Trigger;
}
else
{
tokenInfo.Color = TokenColor.Text;
tokenInfo.Type = TokenType.Unknown;
tokenInfo.Trigger = TokenTriggers.None;
}

tokenInfo.StartIndex = tok.Position;
tokenInfo.EndIndex = lexer.yypos - 1;
}
else
else if (yypos < srcBuf.Length && srcBuf.Contains("--"))
{
tokenInfo.Color = TokenColor.Text;
tokenInfo.Type = TokenType.Unknown;
tokenInfo.Trigger = TokenTriggers.None;
tokenInfo.StartIndex = srcBuf.IndexOf("--", yypos);
tokenInfo.EndIndex = srcBuf.Length;
TokenInfo inf = (TokenInfo)tokenInf["COMMENT"];
tokenInfo.Color = inf.Color;
tokenInfo.Type = inf.Type;
tokenInfo.Trigger = inf.Trigger;
}

tokenInfo.StartIndex = tok.Position;
tokenInfo.EndIndex = lexer.yypos - 1;

else
return false;

return true;
}

public void SetSource(string source, int offset)
{
lexer.Start(source);
srcBuf = source;
while (lexer.yypos < offset)
lexer.Advance();
}
Expand Down
3 changes: 1 addition & 2 deletions LuaLangPack/LuaLangPack/VsPkg.cs
Expand Up @@ -114,8 +114,7 @@ protected override void Dispose(bool disposing)
}

base.Dispose(disposing);
}

}

#region IOleComponent Members

Expand Down
7 changes: 4 additions & 3 deletions LuaLangPack/LuaLangPack/lua.lexer
Expand Up @@ -56,17 +56,18 @@
"false" %FALSE
".." %CONCAT
"..." %ELIPSE
[a-zA-Z][A-Za-z0-9_]* %NAME { s = yytext; }
[a-zA-Z_][A-Za-z0-9_]* %NAME { s = yytext; }
[0-9]+([.][0-9])?[0-9]* %NUMBER { n = Convert.ToDouble(yytext); }


\" { yybegin("LITERAL"); yyl.str = "\"";}
<LITERAL> \\\" { yyl.str += yytext; }
<LITERAL> \\\\ { yyl.str += yytext; }
<LITERAL> [^\"] { yyl.str += yytext; }
<LITERAL> \" { yybegin("YYINITIAL"); yyl.yytext = yyl.str + "\""; return new LITERAL(yyl.yytext); }

"--" { yybegin("COMMENT"); }
<COMMENT> [^\n\r] { }
<COMMENT> \n|\r { yybegin("YYINITIAL"); return new COMMENT(); }
<COMMENT> [^\n] { }
<COMMENT> "\n" { yybegin("YYINITIAL"); }


0 comments on commit 2d33754

Please sign in to comment.