added jj_temporal source code
This commit is contained in:
10
jj_temporal/jj_t/parsers/classes/ymd_time_parser.e
Normal file
10
jj_temporal/jj_t/parsers/classes/ymd_time_parser.e
Normal file
@@ -0,0 +1,10 @@
|
||||
note
|
||||
description: "Summary description for {YMD_TIME_PARSER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
YMD_TIME_PARSER
|
||||
|
||||
end
|
130
jj_temporal/jj_t/parsers/classes/ymd_time_parser_routines.e
Normal file
130
jj_temporal/jj_t/parsers/classes/ymd_time_parser_routines.e
Normal file
@@ -0,0 +1,130 @@
|
||||
note
|
||||
description: "[
|
||||
Routines used by the {YMD_TIME_PARSER}. These were put here to
|
||||
ease the editting. The text of class {YMD_TIME_PARSER} is produced
|
||||
by "geyacc" from a discription file, so every time a change is
|
||||
made "geyacc" must be run (from a dos prompt), the files moved, etc.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2009, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL:$"
|
||||
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class YMD_TIME_PARSER_ROUTINES
|
||||
|
||||
inherit
|
||||
|
||||
YMD_TIME_FORMAT_CONSTANTS
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
YMD_TIME_SCANNER_ROUTINES
|
||||
|
||||
feature -- Access
|
||||
|
||||
format: INTEGER
|
||||
-- How the date should appear (i.e. "dd mmm yyyy", "mm/dd/yy", etc
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_format (a_format: INTEGER)
|
||||
-- Change `format'
|
||||
require
|
||||
valid_format: is_valid_format (a_format)
|
||||
do
|
||||
format := a_format
|
||||
ensure
|
||||
format_was_set: format = a_format
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
process_ambiguous_day (a_possible_day, a_month, a_year: INTEGER): detachable YMD_TIME
|
||||
-- Return a date if `a_possible_day' is valid for the know values of
|
||||
-- `a_month' and `a_year'; void otherwise.
|
||||
require
|
||||
valid_month: a_month >= 1 and a_month <= 12
|
||||
valid_year: a_year /= 0
|
||||
local
|
||||
d: YMD_TIME
|
||||
do
|
||||
create d.set (a_year, a_month, 1)
|
||||
if a_possible_day >= 1 and a_possible_day <= d.last_day_of_month then
|
||||
create Result.set (a_year, a_month, a_possible_day)
|
||||
end
|
||||
end
|
||||
|
||||
process_ambiguous_day_month (a_possible_day, a_possible_month, a_year: INTEGER): YMD_TIME
|
||||
-- Only the year is known; determine which of the other two values is
|
||||
-- the month and which is the day.
|
||||
require
|
||||
valid_year: a_year /= 0
|
||||
unknown_day_from_scanner: a_possible_day <= 12
|
||||
unknown_month_from_scanner: a_possible_month <= 12
|
||||
do
|
||||
create Result.set (a_year, a_possible_month, a_possible_day)
|
||||
end
|
||||
|
||||
process_ambiguous_day_year (a_possible_day, a_month, a_possible_year: INTEGER): YMD_TIME
|
||||
-- Only the month is know for sure.
|
||||
require
|
||||
valid_month: a_month >= 1 and a_month <= 12
|
||||
unknown_day_from_scanner: a_possible_day <= 12
|
||||
unknown_year_from_scanner: a_possible_year <= 12
|
||||
do
|
||||
create Result.set (a_possible_day, a_month, a_possible_year)
|
||||
end
|
||||
|
||||
process_unspecified (a_day, a_month, a_year: INTEGER): YMD_TIME
|
||||
-- One of `a_day' or `a_year' was not specified in the scanned string.
|
||||
-- The unspecified one will be 0.
|
||||
require
|
||||
one_zero: a_day = 0 or a_year = 0
|
||||
valid_month: a_month >= 1 and a_month <= 12
|
||||
local
|
||||
d: YMD_TIME
|
||||
do
|
||||
if a_day = 0 then
|
||||
create Result.set (a_year, a_month, 1)
|
||||
else
|
||||
create d.set_now
|
||||
create Result.set_now
|
||||
Result.set_day (a_day)
|
||||
Result.set_month (a_month)
|
||||
if Result < d then
|
||||
Result.set_year (Result.year + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
process_three_numbers (int_1, int_2, int_3: INTEGER): YMD_TIME
|
||||
-- Scanner encountered a three-integer date and was unable to determine
|
||||
-- from the context what any of them mean.
|
||||
require
|
||||
int_1_is_number: int_1 >= 1 and int_1 <= 31
|
||||
int_2_is_number: int_2 >= 1 and int_2 <= 31
|
||||
int_3_is_number: int_3 >= 1 and int_3 <= 31
|
||||
do
|
||||
|
||||
create Result.set (int_1, int_2, int_3)
|
||||
end
|
||||
|
||||
process_two_numbers (int_1, int_2: INTEGER): YMD_TIME
|
||||
-- Scanner only found 2 numbers and unknow what they represent.
|
||||
require
|
||||
int_1_is_number: int_1 >= 1 and int_1 <= 31
|
||||
int_2_is_number: int_2 >= 1 and int_2 <= 31
|
||||
do
|
||||
create Result.set_now
|
||||
Result.set_day (int_1)
|
||||
Result.set_month (int_2)
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
valid_ymd_time_format: is_valid_format (format)
|
||||
|
||||
end -- Class YMD_TIME_PARSER_ROUTINES
|
69
jj_temporal/jj_t/parsers/classes/ymd_time_scanner_routines.e
Normal file
69
jj_temporal/jj_t/parsers/classes/ymd_time_scanner_routines.e
Normal file
@@ -0,0 +1,69 @@
|
||||
note
|
||||
description: "[
|
||||
Routines used by the {YMD_TIME_SCANNER}. These were put here to
|
||||
ease the editting. The text of class {YMD_TIME_SCANNER} is produced
|
||||
by "gelex" from a discription file, so every time a change is
|
||||
made "geyacc" must be run (from a dos prompt), the files moved, etc.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2009, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL:$"
|
||||
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
YMD_TIME_SCANNER_ROUTINES
|
||||
|
||||
inherit
|
||||
|
||||
YMD_TIME_FORMAT_CONSTANTS
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Inititalization
|
||||
|
||||
default_create
|
||||
|
||||
-- Create an instance
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
last_string: detachable STRING
|
||||
-- Last string value read to pass to parser
|
||||
|
||||
last_integer: INTEGER
|
||||
-- Last integer value read to pass to parser.
|
||||
|
||||
last_value: detachable ANY
|
||||
-- Last value read by the scanner
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
comas_removed (a_number_string: STRING): STRING
|
||||
-- Return the string without comas.
|
||||
-- Used to remove comas from reals or strings.
|
||||
local
|
||||
s: STRING
|
||||
i, n: INTEGER
|
||||
c: CHARACTER
|
||||
do
|
||||
create Result.make (200)
|
||||
s := a_number_string
|
||||
n := a_number_string.count
|
||||
from i := 1 until i > n
|
||||
loop
|
||||
c := s.item (i)
|
||||
if c /= ',' then
|
||||
Result.append_character (c)
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
end -- class YMD_TIME_SCANNER_ROUTINES
|
49
jj_temporal/jj_t/parsers/classes/ymd_time_tokens.e
Normal file
49
jj_temporal/jj_t/parsers/classes/ymd_time_tokens.e
Normal file
@@ -0,0 +1,49 @@
|
||||
note
|
||||
|
||||
description: "Parser token codes"
|
||||
generator: "geyacc version 3.4"
|
||||
|
||||
class YMD_TIME_TOKENS
|
||||
|
||||
|
||||
feature -- Last values
|
||||
|
||||
last_any_value: detachable ANY
|
||||
|
||||
feature -- Access
|
||||
|
||||
token_name (a_token: INTEGER): STRING
|
||||
-- Name of token `a_token'
|
||||
do
|
||||
inspect a_token
|
||||
when 0 then
|
||||
Result := "EOF token"
|
||||
when -1 then
|
||||
Result := "Error token"
|
||||
when SCAN_ERROR_TOKEN then
|
||||
Result := "SCAN_ERROR_TOKEN"
|
||||
when WEEKDAY_TOKEN then
|
||||
Result := "WEEKDAY_TOKEN"
|
||||
when YEAR_TOKEN then
|
||||
Result := "YEAR_TOKEN"
|
||||
when MONTH_TOKEN then
|
||||
Result := "MONTH_TOKEN"
|
||||
when YEAR_OR_DAY_TOKEN then
|
||||
Result := "YEAR_OR_DAY_TOKEN"
|
||||
when NUMBER_TOKEN then
|
||||
Result := "NUMBER_TOKEN"
|
||||
else
|
||||
Result := "Unknown token"
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Token codes
|
||||
|
||||
SCAN_ERROR_TOKEN: INTEGER = 258
|
||||
WEEKDAY_TOKEN: INTEGER = 259
|
||||
YEAR_TOKEN: INTEGER = 260
|
||||
MONTH_TOKEN: INTEGER = 261
|
||||
YEAR_OR_DAY_TOKEN: INTEGER = 262
|
||||
NUMBER_TOKEN: INTEGER = 263
|
||||
|
||||
end
|
Reference in New Issue
Block a user