Skip to main content

module lang::diff::unified::UnifiedDiff

rascal-0.40.16

Syntax definition for Unified Diff format (see http://en.wikipedia.org/wiki/Diff_utility#Unified_format).

Usage

import lang::diff::unified::UnifiedDiff;

syntax Diff

syntax Diff
= Header old Header new Chunk* chunks
;

syntax Chunk

syntax Chunk
= ChunkStart Line+
;

syntax ChunkStart

syntax ChunkStart
= ^ "@@ -" Range " +" Range " @@" Content
;

syntax Header

syntax Header
= ^ Indicator " " FileName DateTime? "\n"
;

syntax DateTime

syntax DateTime
= "\t" Date date " " Time time " " TimeZone timeZone
;

syntax FileName

lexical FileName
= ![\t\n]*
;

syntax Indicator

syntax Indicator
= old: "---"
| new: "+++"
;

syntax Date

syntax Date
= Year year "-" Month month "-" Day day
;

syntax Time

syntax Time
= Hours hours ":" Minutes minutes ":" Seconds seconds [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
;

syntax Year

lexical Year = [0-9][0-9][0-9][0-9];

syntax Month

lexical Month = [0-1][0-9];

syntax Day

lexical Day = [0-1][0-9];

syntax Hours

lexical Hours = [0-2][0-9];

syntax Minutes

lexical Minutes = [0-6][0-9];

syntax Seconds

lexical Seconds = [0-6][0-9];

syntax TimeZone

syntax TimeZone
= Sign sign Hours hours Minutes minutes
;

syntax Sign

lexical Sign = [+\-];

syntax Range

syntax Range
= Decimal begin // chunksize = 1
| Decimal begin "," Decimal size
;

syntax Decimal

lexical Decimal
= [0-9]+ !>> [0-9]
;

syntax Line

syntax Line
= common: ^ " " Content content
| onlyOld: ^ "-" Content content
| onlyNew: ^ "+" Content content
| noNewLine: ^"\\ No newline at end of file\n"
;

syntax Content

lexical Content
= ![\n]* [\n]
;