Is it possible to parse this output with Antlr ?

111 views
Skip to first unread message

Philippe Laval

unread,
Jan 5, 2015, 10:51:07 AM1/5/15
to antlr-di...@googlegroups.com
Sorry, I am a beginner in parsing, so my question may be obvious.
Is it possible to parse this output with antlr ?
I get this output from a VMWare tool so this maybe usefull for a lot of persons.
has someone written a grammar that could be used as an example to modify ?
I see that we have (type), array [] and object {}.


Guest information:
(vim.vm.GuestInfo) {
   dynamicType = <unset>,
   toolsStatus = "toolsOk",
   toolsVersionStatus = "guestToolsCurrent",
   toolsVersionStatus2 = "guestToolsCurrent",
   toolsRunningStatus = "guestToolsRunning",
   toolsVersion = "9349",
   toolsUpdateStatus = (vim.vm.GuestInfo.ToolsUpdateStatus) null,
   guestId = "windows7Server64Guest",
   guestFamily = "windowsGuest",
   guestFullName = "Microsoft Windows Server 2008 R2 (64-bit)",
   hostName = "gechem8dla-2-cl2.asg.com",
   ipAddress = "10.33.6.110",
   net = (vim.vm.GuestInfo.NicInfo) [
      (vim.vm.GuestInfo.NicInfo) {
         dynamicType = <unset>,
         network = "10.33.6.xxx",
         ipAddress = (string) [
            "fe80::6405:beef:8dc0:2586",
            "10.33.6.110"
         ],
         macAddress = "00:0c:29:d6:a5:18",
         connected = true,
         deviceConfigId = 4000,
         dnsConfig = (vim.net.DnsConfigInfo) {
            dynamicType = <unset>,
            dhcp = false,
            hostName = "",
            domainName = "asg.com",
            ipAddress = (string) [
               "10.33.0.39",
               "10.2.2.30"
            ],
         },
         ipConfig = (vim.net.IpConfigInfo) {
            dynamicType = <unset>,
            ipAddress = (vim.net.IpConfigInfo.IpAddress) [
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  ipAddress = "fe80::6405:beef:8dc0:2586",
                  prefixLength = 64,
                  origin = "linklayer",
                  state = "unknown",
                  lifetime = <unset>,
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  ipAddress = "10.33.6.110",
                  prefixLength = 23,
                  origin = "dhcp",
                  state = "preferred",
                  lifetime = <unset>,
               }
            ],
            dhcp = (vim.net.DhcpConfigInfo) {
               dynamicType = <unset>,
               ipv6 = (vim.net.DhcpConfigInfo.DhcpOptions) null,
               ipv4 = (vim.net.DhcpConfigInfo.DhcpOptions) {
                  dynamicType = <unset>,
                  enable = true,
               },
            },
            autoConfigurationEnabled = <unset>,
         },
         netBIOSConfig = (vim.net.NetBIOSConfigInfo) null,
      }
   ],
   ipStack = (vim.vm.GuestInfo.StackInfo) [
      (vim.vm.GuestInfo.StackInfo) {
         dynamicType = <unset>,
         dnsConfig = (vim.net.DnsConfigInfo) {
            dynamicType = <unset>,
            dhcp = false,
            hostName = "gechem8dla-2-cl2",
            domainName = "asg.com",
            ipAddress = (string) [
               "10.33.0.39",
               "10.2.2.30"
            ],
         },
         ipRouteConfig = (vim.net.IpRouteConfigInfo) {
            dynamicType = <unset>,
            ipRoute = (vim.net.IpRouteConfigInfo.IpRoute) [
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "0.0.0.0",
                  prefixLength = 0,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "10.33.6.1",
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "10.33.6.0",
                  prefixLength = 23,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "10.33.6.110",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "10.33.7.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "224.0.0.0",
                  prefixLength = 4,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "255.255.255.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "fe80::",
                  prefixLength = 64,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "fe80::6405:beef:8dc0:2586",
                  prefixLength = 128,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "ff00::",
                  prefixLength = 8,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = <unset>,
                     device = "0",
                  },
               }
            ],
         },
         dhcpConfig = (vim.net.DhcpConfigInfo) null,
      }
   ],
   disk = (vim.vm.GuestInfo.DiskInfo) [
      (vim.vm.GuestInfo.DiskInfo) {
         dynamicType = <unset>,
         diskPath = "C:\",
         capacity = 42841665536,
         freeSpace = 12623646720,
      }
   ],
   screen = (vim.vm.GuestInfo.ScreenInfo) {
      dynamicType = <unset>,
      width = 800,
      height = 600,
   },
   guestState = "running",
   powerPolicy = (vim.vm.PowerPolicy) null,
   appHeartbeatStatus = "appStatusGray",
   appState = "none",
   guestOperationsReady = true,
   interactiveGuestOperationsReady = false,
}

David Whitten

unread,
Jan 5, 2015, 10:58:52 AM1/5/15
to antlr-di...@googlegroups.com
Is this JSON or a variant of JSON ?
> --
> You received this message because you are subscribed to the Google Groups
> "antlr-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to antlr-discussi...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Philippe Laval

unread,
Jan 5, 2015, 11:22:22 AM1/5/15
to antlr-di...@googlegroups.com
It seems to be json but it only looks like.
The output is probably a langage used by VMWare.
I will look at the json grammar if one exist.

Philippe Laval

unread,
Jan 6, 2015, 10:00:31 AM1/6/15
to antlr-di...@googlegroups.com
Hi all,

I have created this grammar that works (it seems).
I have several point that must be improved :

I want to have the '(' and ')' in the rule and not in the CLASS but if I remove thme I will have the two rules that will be the same mostly (so I get a problem).
How can I separate the identier like gateway and class like string or vim.net.IpRouteConfigInfo.Gateway
IDENTIFIER : LETTER (LETTER|DIGIT)*;
CLASS : '(' LETTER (LETTER|DIGIT|'.')* ')' ;

I have also problems with the STRING since I need to parse "", "C:\", "fe80::6405:2586", "10.88.6.110", "Microsoft Windows Server 2008 R2 (64-bit)", "host-cl2.com"
The problem seems to come from "C:\" with the \"
Can anyone give me better rule for teh STRING ?

I will try now to transform the grammar into a parser but this is not easy for me.

Thanks in advance.
Philippe

/*
 * Grammar for VMWare files.
 * v0.1 - 2015
 * Philippe Laval.
 * philippe.laval [at] free.fr
 * Released under MIT license.
 */

grammar VMWARE;

vmware : object
        | array
        ;

object
    : CLASS '{' pair ',' (pair ',')* '}'
        | CLASS NULL    // null object
    | CLASS '{' '}' // empty object
    ;

array
    : CLASS '[' value (',' value)* ']'
    | CLASS '[' ']' // empty array
    ;


value : NUMBER
        | STRING
        | object    // recursion
    | array     // recursion
        | TRUE
        | FALSE
        | NULL
        | UNSET
        ;

pair: IDENTIFIER EQUAL value ;

// parser rules start with lowercase letters, lexer rules with uppercase



// "a numeral [-]?(.[0-9]+ | [0-9]+(.[0-9]*)? )"
//NUMBER :   '-'? ('.' DIGIT+ | DIGIT+ ('.' DIGIT*)? ) ;
// INT :   DIGIT+ ;             // Define token INT as one or more digits

STRING : '"' ([a-zA-Z0-9]
             |' '           
             |'.'
             |':'   
             |'('  
             |')'  
             |'-'   
             |'\\' )* '"' ;

// "any double-quoted string ("...") possibly containing escaped quotes"
    // this break the line
    //diskPath = "C:\",
// STRING : '"' ('\\"'|.)*? '"' ;

// this break the line
//diskPath = "C:\",
// STRING : '"' (ESC | ~["\\])* '"' ;
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
fragment UNICODE : 'u' HEX HEX HEX HEX ;
fragment HEX : [0-9a-fA-F] ;

NUMBER
: '-'? INT '.' [0-9]+ EXP? // 1.35, 1.35E-9, 0.3, -4.5
| '-'? INT EXP // 1e10 -3e4
| '-'? INT // -3, 45
;

EQUAL : '=' ;
TRUE : 'true' ;
FALSE : 'false' ;
NULL : 'null' ;
UNSET : '<unset>' ;

// IDENTIFIER : [a-zA-Z]([a-zA-Z]|[a-zA-Z0-9])* ;
IDENTIFIER : LETTER (LETTER|DIGIT)*;

CLASS : '(' LETTER (LETTER|DIGIT|'.')* ')' ;

fragment LETTER : [a-zA-Z\u0080-\u00FF_] ;
// fragment DIGIT : '0'..'9' ;
fragment DIGIT : [0-9] ;
fragment INT : '0' | [1-9] [0-9]* ; // no leading zeros
fragment EXP : [Ee] [+\-]? INT ; // \- since - means "range" inside [...]

WS  :   [ \t\r\n]+ -> skip ; // Define whitespace rule, toss it out
Reply all
Reply to author
Forward
0 new messages