From b64ab957671f80b1c6cb2a66135fcfac2cabf48b Mon Sep 17 00:00:00 2001 From: Frank Maritato Date: Fri, 16 Apr 2010 00:57:26 +0000 Subject: [PATCH] string, numeric and boolean literals all work git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-java/trunk@440 a2f82657-cdd2-4550-bd36-68a8e7111808 --- pom.xml | 6 +++ src/main/javacc/ESFParser.jj | 72 +++++++++++++++++++++----- src/test/java/org/lwes/db/DefaultValueTest.esf | 12 +++-- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index e32d137..38c747a 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,12 @@ javacc + + + diff --git a/src/main/javacc/ESFParser.jj b/src/main/javacc/ESFParser.jj index a1c22b1..ec7f682 100644 --- a/src/main/javacc/ESFParser.jj +++ b/src/main/javacc/ESFParser.jj @@ -57,9 +57,14 @@ TOKEN : { < REQ: "required" > | < OPT: "optional" > + | < TRUE: "true" > + | < FALSE: "false" > | < ID: ["a"-"z","A"-"Z","_",":","0"-"9","."] (["a"-"z","A"-"Z","_",":","0"-"9","."])* > | < LBRACKET: "[" > | < RBRACKET: "]" > + | < INTEGER_LITERAL: ["1"-"9"] (["0"-"9"])* > + | < STRING_LITERAL: "\""()"\"" > + } /** @@ -120,24 +125,63 @@ int arraySize() : } } -Object defaultValue() : +String StringLiteral() : { Token t; } { - t = + t = { - if (t.image.equals("true") || t.image.equals("false")) { - return Boolean.parseBoolean(t.image); - } - else { - try { - return Integer.parseInt(t.image); - } - catch(NumberFormatException e) { - return Double.parseDouble(t.image); - } - } + return t.image; + } +} + +boolean BooleanLiteral() : +{} +{ + + { + return true; + } + | + + { + return false; + } +} + +int IntegerLiteral() : +{ + Token t; +} +{ + t = + { + Log.debug("INTEGER LITERAL"); + try { + return Integer.parseInt(t.image); + } catch (NumberFormatException e) { + throw new Error(); + } + } +} + +Object defaultValue() : +{ + Object obj; +} +{ + obj = IntegerLiteral() + { + return obj; + } + | obj = BooleanLiteral() + { + return obj; + } + | obj = StringLiteral() + { + return obj; } } @@ -152,7 +196,7 @@ void attribute() : { ((("required" {required = true;} | "optional") (aType=type() anAttribute=attributeName() [ "[" anArraySize = arraySize() "]" ] [ "=" aDefaultValue = defaultValue() ] ";")) | - (aType=type() anAttribute=attributeName() [ "[" anArraySize = arraySize() "]" ] ";") ) { + (aType=type() anAttribute=attributeName() [ "[" anArraySize = arraySize() "]" ] [ "=" aDefaultValue = defaultValue() ] ";") ) { if ( !( aType.equals("uint16") || aType.equals("int16") || aType.equals("uint32") || diff --git a/src/test/java/org/lwes/db/DefaultValueTest.esf b/src/test/java/org/lwes/db/DefaultValueTest.esf index 9dc5424..60db864 100644 --- a/src/test/java/org/lwes/db/DefaultValueTest.esf +++ b/src/test/java/org/lwes/db/DefaultValueTest.esf @@ -6,13 +6,17 @@ MetaEventInfo int16 enc; # encoding of strings in the event; 0: iso-8859-1, 1: utf-8 uint16 SiteID; # id of site sending the event - #string version = "1.0.0"; # event version + required string version = "1.0.0"; + string versionOpt = "1.0.1"; # event version } # Debugging messages DefaultValueEvent { - required int32 anInt = 5; - #required float pi = 3.141594; # numeric default value - optional boolean aBool = true; # boolean default value + optional boolean aBool = true; # boolean default value + boolean aBoolOpt = false; # boolean default value + required int32 anInt = 5; + int32 anIntOpt = 6; + #required float pi = 3.141594; # numeric default value + # float piOpt = 3.141594; # numeric default value } \ No newline at end of file -- 2.11.4.GIT