Skip to content

Commit

Permalink
Braces fixed again
Browse files Browse the repository at this point in the history
  • Loading branch information
proninis committed Mar 31, 2014
1 parent 6091b6d commit be4b857
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
44 changes: 44 additions & 0 deletions byond2Lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import byond2Common;

////////////////////////////////////////////////////////////////////////////////
// token flow control
@lexer::header
{
import java.util.Stack;
}

@lexer::members
{
Expand All @@ -12,6 +16,10 @@ import byond2Common;
private int prevTokenType = EOF;
private String fileName = null;
private int macroStartCharPositionInLine;
private int nestingBraces = 0;
private int indentLevelBraced = 0;
private Stack<Integer> indentLevelBracedStack =
new Stack<Integer>();
@Override
public String getSourceName()
Expand All @@ -31,6 +39,11 @@ import byond2Common;

private void indent(int n)
{
if (nestingBraces > 0)
{
indentLevelBraced += n;
}

indentLevel += n;
while (n > 0)
{
Expand All @@ -41,6 +54,11 @@ import byond2Common;

private void dedent(int n)
{
if (nestingBraces > 0)
{
indentLevelBraced -= n;
}

indentLevel -= n;
while (n > 0)
{
Expand Down Expand Up @@ -192,6 +210,32 @@ import byond2Common;
parseMacroLine(macro);
break;

case LCURV:
nestingBraces++;

indentLevelBracedStack.push(indentLevelBraced);
indentLevelBraced = 0;

pendingTokens.add(token);
break;

case RCURV:
if (indentLevelBraced > 0)
{
dedent(indentLevelBraced);
indentLevelBraced = 0;
}

nestingBraces--;

if (!indentLevelBracedStack.isEmpty())
{
indentLevelBraced = indentLevelBracedStack.pop();
}

pendingTokens.add(token);
break;

case EOF:
dedentAll();

Expand Down
10 changes: 2 additions & 8 deletions byond2Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ statementLine
: statement (SEMI statement?)*
;

blockBracedEnd
:
( RCURV (newline? DEDENT)? (newline? DEDENT)*?
| (DEDENT newline)* RCURV)
;

blockBraced
: LCURV statementLine?
( RCURV
| (newline (INDENT (blockInner newline?)?)?)? blockBracedEnd)
| (newline (INDENT (blockInner newline?)? DEDENT newline)?)? RCURV)
;

blockIndented
Expand Down Expand Up @@ -87,7 +81,7 @@ statementProcLine
blockBracedProc
: LCURV statementProcLine?
( RCURV
| (newline (INDENT (blockInnerProc newline?)?)?)? blockBracedEnd)
| (newline (INDENT (blockInnerProc newline?)? DEDENT newline)?)? RCURV)
;

blockIndentedProc
Expand Down
6 changes: 2 additions & 4 deletions testf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#java -Xmx512M -cp .:/media/usb3/media/download/antlr-4.2-complete.jar Main $1

java -Xmx768M -cp .:/media/usb3/media/download/antlr-4.2-complete.jar Main \
"/media/usb3/Baystation12/Baystation12/code/modules/awaymissions/maploader/writer.dm"
#"/media/usb3/Baystation12/Baystation12/code/__HELPERS/icons.dm"
#/media/usb3/Baystation12/Baystation12/code/modules/awaymissions/maploader/dmm_suite.dm
#"/media/usb3/byond-port/test.dm"
"/media/usb3/byond-port/test.dm"
#"/media/usb3/byond-port/test.pre"
#"/media/usb3/Baystation12/Baystation12/baystation12.dme"

0 comments on commit be4b857

Please sign in to comment.