/*
 * xtc - The eXTensible Compiler
 * Copyright (C) 2004-2006 Robert Grimm, New York University
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 * USA.
 */

/**
 * Definition of Java constants.
 *
 * @author Robert Grimm
 * @author Stacey Kuznetsov
 * @version $Revision: 1.6 $
 */
module xtc.lang.JavaConstant(Identifier, Spacing);

import Identifier;
import Spacing;

Node Literal =
    FloatingPointLiteral Spacing
  / IntegerLiteral Spacing
  / CharacterLiteral Spacing
  / StringLiteral Spacing
  / BooleanLiteral
  / NullLiteral
  ;

// ----- Integer literals

generic IntegerLiteral =
    <Hex> 	HexLiteral    
  / <Octal>   	OctalLiteral
  / <Decimal> 	DecimalLiteral
  ;

transient String HexLiteral =  HexNumeral     IntegerTypeSuffix? ;
transient String OctalLiteral = OctalNumeral   IntegerTypeSuffix? ;
transient String DecimalLiteral = DecimalNumeral IntegerTypeSuffix? ;

transient String DecimalNumeral    = '0' / NonZeroDigit Digit* ;
transient String NonZeroDigit      = [1-9] ;
transient String Digit             = [0-9] ;

transient String HexNumeral        = '0' [xX] HexDigit+ ;
transient String HexDigit          = [0-9a-fA-F] ;

transient String OctalNumeral      = '0' OctalDigit+ ;
transient String OctalDigit        = [0-7] ;

transient String IntegerTypeSuffix = [lL] ;

// ----- Floating point literals

generic FloatingPointLiteral = FloatingPointString;

String FloatingPointString =
    Digit+ '.' Digit* Exponent? FloatTypeSuffix?
  /        '.' Digit+ Exponent? FloatTypeSuffix?
  / Digit+            Exponent  FloatTypeSuffix?
  / Digit+            Exponent? FloatTypeSuffix
  ;

transient String Exponent        = [eE] [+\-]? Digit+ ;
transient String FloatTypeSuffix = [fFdD] ;

// ----- Character and string constants

generic CharacterLiteral = CharacterConstant ;
generic StringLiteral    = StringConstant    ;

String CharacterConstant = ['] ( EscapeSequence / !['\\] _ )  ['] ;
String StringConstant    = ["] ( EscapeSequence / !["\\] _ )* ["] ;

transient String EscapeSequence =
  '\\' [btnfr"'\\] / UnicodeEscape / OctalEscape ;

transient String OctalEscape    =
  '\\' [0-3] OctalDigit OctalDigit
  / '\\' OctalDigit OctalDigit
  / '\\' OctalDigit
  ;

transient String UnicodeEscape  =
  '\\' 'u' HexDigit HexDigit HexDigit HexDigit ;

// ----- Boolean literals

inline generic BooleanLiteral =
    "true":Word
  / "false":Word
  ;

// ----- Null literals

inline generic NullLiteral =
  void:"null":Word
  ;
