/* * L9Script.g - ANTLR grammar for Level9.net script files. * * Copyright (C) 2004 - 2011 Andreas Scherrer * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software 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 software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ lexer grammar L9Script; options { language = CSharp2; } @header { using System.Text; using Level9; } @members { string format(string text) { StringBuilder builder = new StringBuilder(text); builder.Replace("\t", " "); builder.Replace("\r\n", " "); builder.Replace("\n", " "); return builder.ToString().Trim(); } public override void ReportError(RecognitionException e) { Script.Instance.Errors.Add(new LexerError( this.GetErrorMessage(e, this.TokenNames), e.Line, e.CharPositionInLine)); } } TITLE : '#' WS* ('title'|'Title'|'TITLE') WS* ':' t = HEADER_TEXT ';' { if (t != null) { Script.Instance.Title = format(t.Text); } } ; COMMENT : '#' WS* ('comment'|'Comment'|'COMMENT') WS* ':' t = HEADER_TEXT ';' { if (t != null) { Script.Instance.Comment = format(t.Text); } } ; COMMAND : t = COMMAND_TEXT ('[' n = NOTE_TEXT ']')? WS* ';' { if (t != null) { Script.Instance.AddEntry(new ScriptEntry(format(t.Text), (n != null ? format(n.Text) : null))); } } ; fragment HEADER_TEXT : (~';')* ; fragment COMMAND_TEXT : (~( WS |'['|';')) (~('['|';'))* ; fragment NOTE_TEXT : (~']')* ; WS : ('\r'|'\t'|'\u000C'|'\n'|' ') ;