Skip to content

Commit 880f4fc

Browse files
committed
Merge branch 'master' into unity-staging
2 parents eb9fe2f + 4e71aaa commit 880f4fc

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

src/UnityScript.Tests/ParserTestFixture.boo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ partial class ParserTestFixture(AbstractCompilerTestFixture):
1818
result = CompileTestCase(StringInput("empty", ""))
1919
Assert.AreEqual(0, len(result.Errors), result.Errors.ToString(true))
2020
Assert.AreEqual(1, len(result.CompileUnit.Modules))
21-
Assert.AreEqual("empty", result.CompileUnit.Modules[0].LexicalInfo.FileName)
21+
22+
module = result.CompileUnit.Modules[0]
23+
Assert.AreEqual("empty", module.Name)
24+
Assert.AreEqual("empty", module.LexicalInfo.FileName)
2225

2326

src/UnityScript/Parser/CodeFactory.boo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import Boo.Lang.Compiler.Ast
55

66
static class CodeFactory:
77

8+
def NewModule(fileName as string):
9+
return Module(LexicalInfo(fileName, 1, 1), Name: ModuleNameFromFileName(fileName))
10+
811
def NewArrayComprehension(location as LexicalInfo, projection as Expression, variable as Declaration, expression as Expression, filter as Expression):
912
ge = GeneratorExpression(location, Expression: projection, Iterator: expression)
1013
ge.Declarations.Add(variable)
@@ -35,3 +38,6 @@ static class CodeFactory:
3538
def WithLocation[of T(Node)](node as T, location as LexicalInfo):
3639
node.LexicalInfo = location
3740
return node
41+
42+
def ModuleNameFromFileName(fname as string):
43+
return System.IO.Path.GetFileNameWithoutExtension(fname)

src/UnityScript/Parser/UnityScriptParser.boo

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ partial class UnityScriptParser(antlr.LLkParser):
253253
li = ToLexicalInfo(LT(1))
254254
ReportError(UnityScriptCompilerErrors.SemicolonExpected(li))
255255

256-
static def CreateModuleName(fname as string):
257-
return System.IO.Path.GetFileNameWithoutExtension(fname)
258-
259256
static def IsConstructorName(name as string, type as TypeDefinition):
260257
return type.NodeType != NodeType.Module and name == type.Name
261258

@@ -322,8 +319,7 @@ partial class UnityScriptParser(antlr.LLkParser):
322319
) as void: //throws RecognitionException, TokenStreamException
323320

324321
eof as IToken = null
325-
module = Module(LexicalInfo(getFilename(), 1, 1))
326-
module.Name = CreateModuleName(getFilename())
322+
module = CodeFactory.NewModule(getFilename())
327323
cu.Modules.Add(module)
328324
globals = module.Globals
329325

src/UnityScript/Parser/UnityScriptParserExtensions.boo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ partial class UnityScriptParser:
1010
static def ParseReader(reader as TextReader, fileName as string, context as CompilerContext, targetCompileUnit as CompileUnit):
1111
lexer = UnityScriptLexerFor(reader, fileName, TabSizeFromContext(context))
1212
if lexer is null:
13-
targetCompileUnit.Modules.Add(Module(LexicalInfo(fileName, 1, 1)))
13+
targetCompileUnit.Modules.Add(CodeFactory.NewModule(fileName))
1414
return
1515

1616
parser = UnityScriptParser(lexer, CompilerContext: context)

src/UnityScript/UnityScript.g

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ tokens
231231
li = ToLexicalInfo(LT(1))
232232
ReportError(UnityScriptCompilerErrors.SemicolonExpected(li))
233233

234-
static def CreateModuleName(fname as string):
235-
return System.IO.Path.GetFileNameWithoutExtension(fname)
236-
237234
static def IsConstructorName(name as string, type as TypeDefinition):
238235
return type.NodeType != NodeType.Module and name == type.Name
239236

@@ -276,8 +273,7 @@ tokens
276273

277274
start[CompileUnit cu]
278275
{
279-
module = Module(LexicalInfo(getFilename(), 1, 1))
280-
module.Name = CreateModuleName(getFilename())
276+
module = CodeFactory.NewModule(getFilename())
281277
cu.Modules.Add(module)
282278
globals = module.Globals
283279
}:

0 commit comments

Comments
 (0)