OK, I removed the string rule from the token list of lexer rules, and now I get what I want from the following source:
import (
"fmt"
_ "hello/suppress"
mux "github.com/gorilla/mux"
"../LingualDomain"
"net/http"
)The above is parsed into the following (desired) AST tree:
FILE([0-3811][0:0])
PACKAGE([0-14][1:1]): {NAME = Server}
IMPORT([599-7051 [19:1])
PKG([611-616][20 2]) {NAMEPART = fmt, NAME = "fmt"}
PKG([619-637][21 2]) {ALIAS = _, QUALIFIER = hello, NAMEPART = suppress, NAME = "hello/suppress")
PKG([640-668][22 2]) {ALIAS = mux, QUALIFIER = github.com, QUALIFIER = gorilla, NAMEPART = mux, NAME = "github.com/gorilla/mux"}
PKG([671-689][23 2]) {QUALIFIER = .., NAMEPART = LingualDomain, NAME = "../LingualDomain"}
PKG([692-702][24 2]) {QUALIFIER = net, NAMEPART = http, NAME = "net/http"}
VARIABLE([709-752][27:1])... asoI used thie following expression to extract the above info:
<importDeclaration> ::= node("IMPORT", "import" "(" <importPackage>* ")" ) ;
<importPackage> ::= node("PKG", [attribute("ALIAS", <IDENTIFIER>)] attribute("NAME", (<importQualifiedName>| <stringliteral>) ) );
<importQualifiedName> ::= "\"" (attribute("QUALIFIER", (<qualifiedName> | [".."])) "/")* attribute("NAMEPART", <qualifiedName> ) "\"";
Comments still suffer from the same problem which stopped this solution earlier (that is, comment being defined as a token makes it not very useful in expressions for picking them up for further processing).
// Rolf