-
Notifications
You must be signed in to change notification settings - Fork 26
Added the Date/Time language by Dennis Prüne #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SchmidtMarc
wants to merge
10
commits into
dev
Choose a base branch
from
date-time-language
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3e2fb15
Added the Date/Time language by Dennis Prüne
SchmidtMarc db9fe34
Changed visibility from private to protected
SchmidtMarc b2bcb1c
Removed TODO
SchmidtMarc d91fb56
Added copyright
SchmidtMarc 2e6f6f7
Fixed mill init
SchmidtMarc b6bde54
Removed temporal languages from the TR grammar input set
SchmidtMarc d2b7965
WIP: debug failing ci test
jra-se 6b26ebc
WIP: debug failing ci test
jra-se 69b1526
WIP: debug failing ci test
jra-se 005840f
revert ci debugging messages
jra-se File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
monticore-grammar/src/main/grammars/de/monticore/temporal/DETemporals.mc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package de.monticore.temporal; | ||
|
|
||
| /* Alpha-version: This is intended to become a MontiCore stable grammar. */ | ||
|
|
||
| /** | ||
| * This grammar realizes the core interfaces defined in TemporalBasis with the DIN date/time standard. | ||
| * | ||
| * These date/time-formats are commonly used in German speaking regions. | ||
| */ | ||
| component grammar DETemporals extends de.monticore.temporal.TemporalBasis { | ||
|
|
||
| interface DEInstant extends Instant; | ||
|
|
||
| interface DEDate extends Date, DEInstant; | ||
|
|
||
| DENumericDate implements DEDate = | ||
| ((daySource:Digits ".")? monthSource:Digits ".")? yearSource:Digits; | ||
|
|
||
| DEAlphanumericDate implements DEDate, Literal = | ||
| (daySource:Digits ".")? monthSource:DEMonth yearSource:Digits; | ||
|
|
||
| DETime implements Time, DEInstant, Literal = | ||
| hourSource:Digits (":" minuteSource:Digits)? (":" secondSource:Digits)? "Uhr"; | ||
|
|
||
| nokeyword "Uhr"; | ||
|
|
||
| DEDateTime implements DateTime, DEInstant, Literal = | ||
| date:DEDate time:DETime; | ||
|
|
||
| /** | ||
| * Defines the German months in their full and abbreviated variant. | ||
| */ | ||
| DEMonth = | ||
| month:[ january:"Januar" | january:"Jan." | ||
| | february:"Februar" | february:"Feb." | ||
| | march:"März" | march:"Mär." | ||
| | april:"April" | april:"Apr." | ||
| | may:"Mai" | may:"Mai." | ||
| | june:"Juni" | june:"Jun." | ||
| | july:"Juli" | july:"Jul." | ||
| | august:"August" | august:"Aug." | ||
| | september:"September" | september:"Sep." | ||
| | october:"Oktober" | october:"Okt." | ||
| | november:"November" | november:"Nov." | ||
| | december:"Dezember" | december:"Dez." ]; | ||
|
|
||
| nokeyword "Januar", "Februar", | ||
| "April", "Mai", "Juni", "Juli", | ||
| "August", "September", "Oktober", | ||
| "November", "Dezember"; | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
monticore-grammar/src/main/grammars/de/monticore/temporal/EscapedTemporalLiterals.mc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package de.monticore.temporal; | ||
|
|
||
| /* Alpha-version: This is intended to become a MontiCore stable grammar. */ | ||
|
|
||
| /** | ||
| * This grammar makes arbitrary temporal values usable in expressions by defining an escaping rule. | ||
| * | ||
| * In short, any temporal value t can be turned into an EscapedTemporalLiteral by writing d"t". | ||
| */ | ||
| component grammar EscapedTemporalLiterals extends de.monticore.temporal.TemporalBasis { | ||
|
|
||
| /** | ||
| * The only production of EscapedTemporalLiterals, making it possible to use any Instant or Period | ||
| * as a Literal (and thus within a Expression via LiteralExpression). | ||
| * | ||
| * Normally, we would split this production into multiple ones to avoid the explicit optional. | ||
| * However, that would cause ambiguity during the parse. | ||
| */ | ||
| EscapedTemporalLiteral implements Literal = "d\"" (Instant | Period) "\""; | ||
|
|
||
| } |
150 changes: 150 additions & 0 deletions
150
monticore-grammar/src/main/grammars/de/monticore/temporal/ISOTemporals.mc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package de.monticore.temporal; | ||
|
|
||
| /* Alpha-version: This is intended to become a MontiCore stable grammar. */ | ||
|
|
||
| /** | ||
| * This grammar realizes the core interfaces defined in TemporalBasis with the ISO 8601-1 standard. | ||
| * | ||
| * These date/time-formats are suitable for use in international communication. | ||
| */ | ||
| component grammar ISOTemporals extends de.monticore.temporal.TemporalBasis { | ||
|
|
||
| interface ISOInstant extends Instant <110>; | ||
|
|
||
| /* ======================================================================== */ | ||
| /* ================================= Date ================================= */ | ||
| /* ======================================================================== */ | ||
|
|
||
| interface ISODate extends ISOInstant, Date; | ||
|
|
||
| CalendarDate implements ISODate = { !isOrdinalDate() }? Sign? pre:Digits ("-" mid:Digits)? ("-" post:Digits)?; | ||
|
|
||
| astrule CalendarDate = | ||
| century: java.util.Optional<Integer> | ||
| decade: java.util.Optional<Integer> | ||
| year: java.util.Optional<Integer> | ||
| month: java.util.Optional<Integer> | ||
| day: java.util.Optional<Integer>; | ||
|
|
||
| OrdinalDate implements ISODate = { isOrdinalDate() }? Sign? pre:Digits ("-" post:Digits)?; | ||
|
|
||
| astrule OrdinalDate = | ||
| year: int | ||
| dayOfYear: int; | ||
|
|
||
| interface WeekDate extends ISODate; | ||
|
|
||
| BasicWeekDate implements WeekDate, Literal = source:BasicWeekDateToken; | ||
|
|
||
| ExtendedWeekDate implements WeekDate = Sign? yearSource:Digits "-" weekSource:WDigits ("-" dayOfWeekSource:Digits)?; | ||
|
|
||
| astrule BasicWeekDate = | ||
| year: int | ||
| week: int | ||
| dayOfWeekInternal: java.util.Optional<Integer>; | ||
|
|
||
| // A 'W' followed by any number of digits ('0'-'9'). Only used above for the WeekDate rule | ||
| // to work around the fact such strings are tokenized as Names. | ||
| WDigits = { cmpTokenRegEx(1, "W\\d+") }? source:Name; | ||
|
|
||
| enum Sign = plus:"+" | minus:"-"; | ||
|
|
||
| /* ======================================================================== */ | ||
| /* ================================= Time ================================= */ | ||
| /* ======================================================================== */ | ||
|
|
||
| ISOTime implements ISOInstant, Time = | ||
| // Basic format | ||
| (preWithT:TDigits Fraction? timeShiftSource:TimeShift?) | ||
| // Extended format | ||
| | ((pre:Digits | preWithT:TDigits) ":" mid:Digits (":" post:Digits)? | ||
| Fraction? timeShiftSource:TimeShift?); | ||
|
|
||
| astrule ISOTime = | ||
| hour: int | ||
| minute: java.util.Optional<Integer> | ||
| second: java.util.Optional<Integer> | ||
| decimalDigits: java.util.Optional<String> | ||
| timeShift: java.util.Optional<Integer>; | ||
|
|
||
| // A 'T' followed by any number of digits ('0'-'9') and possibly a 'Z' as the last character. | ||
| // Only used above, to work around the fact that strings such as "T123001Z" will be tokenized | ||
| // as a single Name token. | ||
| TDigits = { cmpTokenRegEx(1, "T\\d+Z?") }? source:Name; | ||
|
|
||
| Fraction = (period:"." | comma:",") Digits; | ||
|
|
||
| TimeShift = "Z" | Sign pre:Digits (":" post:Digits)?; | ||
|
|
||
| /* ======================================================================== */ | ||
| /* =============================== DateTime =============================== */ | ||
| /* ======================================================================== */ | ||
|
|
||
| ISODateTime implements ISOInstant, Literal, DateTime = source:ISODateTimeToken; | ||
|
|
||
| astrule ISODateTime = | ||
| date: ISODate | ||
| time: ISOTime; | ||
|
|
||
| /* ======================================================================== */ | ||
| /* ================================ Period ================================ */ | ||
| /* ======================================================================== */ | ||
|
|
||
| interface ISOPeriod extends Period; | ||
|
|
||
| FullPeriod implements ISOPeriod = pre:PeriodBegin (Fraction post:PeriodEnd)?; | ||
|
|
||
| PeriodBegin = { cmpTokenRegEx(1, "P(\\d+Y)?(\\d+M)?(\\d+D)?T?(\\d+[hH])?(\\d+[mM])?(\\d+[sS])?\\d*") }? source:Name; | ||
|
|
||
| PeriodEnd = { cmpTokenRegEx(1, "[hHmMsS]") }? source:Name; | ||
|
|
||
| astrule FullPeriod = | ||
| years: java.util.Optional<Integer> | ||
| months: java.util.Optional<Integer> | ||
| days: java.util.Optional<Integer> | ||
| hours: java.util.Optional<Integer> | ||
| minutes: java.util.Optional<Integer> | ||
| seconds: java.util.Optional<Integer> | ||
| decimalDigits: java.util.Optional<String>; | ||
|
|
||
| WeekPeriod implements ISOPeriod = { cmpTokenRegEx(1, "P[0-9]+W") }? source:Name; | ||
|
|
||
| astrule WeekPeriod = | ||
| weeks: int; | ||
|
|
||
| /* ======================================================================== */ | ||
| /* ================================ Tokens ================================ */ | ||
| /* ======================================================================== */ | ||
|
|
||
| fragment token SignToken = '+' | '-'; | ||
|
|
||
| fragment token BasicTime = 'T' Digits; | ||
|
|
||
| fragment token ExtendedTime = 'T'? Digits ':' Digits (':' Digits)?; | ||
|
|
||
| fragment token FractionToken = ('.' | ',') Digits; | ||
|
|
||
| fragment token TimeShiftToken = 'Z' | SignToken Digits (':' Digits)?; | ||
|
|
||
| fragment token ISOTimeToken = (BasicTime | ExtendedTime) FractionToken? TimeShiftToken?; | ||
|
|
||
| token BasicWeekDateToken = SignToken? Digits 'W' Digits; | ||
|
|
||
| token ISODateTimeToken = SignToken? Digits '-'? 'W'? Digits ('-' Digits)? ISOTimeToken; | ||
|
|
||
| concept antlr { | ||
| parserjava { | ||
| public boolean isOrdinalDate() { | ||
| int extraDigits = 0; | ||
| int tokenIndex = 1; | ||
| if (cmpToken(tokenIndex, "+", "-")) { | ||
| tokenIndex++; | ||
| extraDigits = 2; | ||
| } | ||
|
|
||
| return getToken(tokenIndex).length() == 7 + extraDigits | ||
| || (cmpToken(tokenIndex + 1, "-") && getToken(tokenIndex + 2).length() == 3); | ||
| } | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
monticore-grammar/src/main/grammars/de/monticore/temporal/TemporalBasis.mc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package de.monticore.temporal; | ||
|
|
||
| /* Alpha-version: This is intended to become a MontiCore stable grammar. */ | ||
|
|
||
| /** | ||
| * This grammar defines the core interfaces for temporal values. | ||
| * | ||
| * These interfaces are realized by conservative extensions of this grammar, each covering | ||
| * a collection of date/time-formats. Currently these extensions are: | ||
| * - ISOTemporals - Covering the ISO-8601 standard, for international use | ||
| * - DETemporals - Covering the DIN date/time standard, used in Germany | ||
| * | ||
| * To enable the use of temporal values as literals there is also the EscapedTemporalLiterals | ||
| * extension. | ||
| */ | ||
| component grammar TemporalBasis extends de.monticore.literals.MCCommonLiterals { | ||
|
|
||
| /*========================================================================*/ | ||
| /*=========================== Core Interfaces ============================*/ | ||
| /*========================================================================*/ | ||
|
|
||
| /** | ||
| * A point on the time scale. Sub-interfaces differ in their granularity, e.g. the unit of a Date | ||
| * is 1 day, while the unit of Time is 1 second. | ||
| */ | ||
| interface Instant; | ||
|
|
||
| /** | ||
| * An Instant whose time components can range from centuries to days. | ||
| */ | ||
| interface Date extends Instant; | ||
|
|
||
| /** | ||
| * An Instant whose time components can range from hours to fractions of a second. | ||
| */ | ||
| interface Time extends Instant; | ||
|
|
||
| /** | ||
| * An Instant which can range over all time components. | ||
| */ | ||
| interface DateTime extends Instant; | ||
|
|
||
| /** | ||
| * A length of time. | ||
| */ | ||
| interface Period; | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.