Add line number tracking in elements parsed using LuaParser.

This commit is contained in:
James Roseborough
2012-09-01 15:56:09 +00:00
parent e0e2452d74
commit 2bf4c5767b
13 changed files with 637 additions and 472 deletions

View File

@@ -21,7 +21,7 @@
******************************************************************************/
package org.luaj.vm2.ast;
public class Chunk {
public class Chunk extends SyntaxElement {
public final Block block;
public Chunk(Block b) {

View File

@@ -25,7 +25,7 @@ import org.luaj.vm2.Lua;
import org.luaj.vm2.LuaValue;
abstract
public class Exp {
public class Exp extends SyntaxElement {
abstract public void accept(Visitor visitor);
public static Exp constant(LuaValue value) {

View File

@@ -26,7 +26,7 @@ import java.util.List;
import org.luaj.vm2.LuaString;
public class FuncArgs {
public class FuncArgs extends SyntaxElement {
public final List<Exp> exps;

View File

@@ -21,7 +21,7 @@
******************************************************************************/
package org.luaj.vm2.ast;
public class FuncBody {
public class FuncBody extends SyntaxElement {
public ParList parlist;
public Block block;
public NameScope scope;

View File

@@ -24,7 +24,7 @@ package org.luaj.vm2.ast;
import java.util.ArrayList;
import java.util.List;
public class FuncName {
public class FuncName extends SyntaxElement {
// example: a.b.c.d:e
// initial base name: "a"

View File

@@ -24,7 +24,7 @@ package org.luaj.vm2.ast;
import java.util.ArrayList;
import java.util.List;
public class ParList {
public class ParList extends SyntaxElement {
public static final List<Name> EMPTY_NAMELIST = new ArrayList<Name>();
public static final ParList EMPTY_PARLIST = new ParList(EMPTY_NAMELIST,false);

View File

@@ -26,7 +26,7 @@ import java.util.List;
import org.luaj.vm2.ast.Exp.VarExp;
abstract
public class Stat {
public class Stat extends SyntaxElement {
public abstract void accept(Visitor visitor);
public static Stat block(Block block) {

View File

@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2012 Luaj.org. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package org.luaj.vm2.ast;
/** Base class for syntax elements of the parse tree that appear in source files.
* The LuaParser class will fill these values out during parsing for use in
* syntax highlighting, for example.
*/
public class SyntaxElement {
/** The line number on which the element begins. */
public int beginLine;
/** The column at which the element begins. */
public short beginColumn;
/** The line number on which the element ends. */
public int endLine;
/** The column at which the element ends. */
public short endColumn;
}

View File

@@ -21,7 +21,7 @@
******************************************************************************/
package org.luaj.vm2.ast;
public class TableField {
public class TableField extends SyntaxElement {
public final Exp index;
public final String name;

File diff suppressed because it is too large Load Diff

View File

@@ -30,10 +30,10 @@ public class SimpleCharStream
protected char[] buffer;
protected int maxNextCharInd = 0;
protected int inBuf = 0;
protected int tabSize = 8;
protected int tabSize = 1;
protected void setTabSize(int i) { tabSize = i; }
protected int getTabSize(int i) { return tabSize; }
public void setTabSize(int i) { tabSize = i; }
public int getTabSize(int i) { return tabSize; }
protected void ExpandBuff(boolean wrapAround)