0

My goal is to generate code for html file using string template. html file contains some ajax code where we need dollar sign. I am not able to print $ dollar sign using string template file, as $ dollar sign denotes EOF in string template.

code for client.html file is shown below:

<script>
$(document).ready(function () {
//Device developer will specify maxDataPoints display in a chart at a time
    var maxDataPoints = 10;
    //Device developer will specify type of charts 
    var chart = new google.visualization.LineChart($('#chart')[0]); 
    var data = google.visualization.arrayToDataTable([ 
    // Device developer will specify what kind of data to be display in chart .....(A)
        ['Time', 'Temperature'],
        [getTime(), 0]
    ]); 
    var options = { 
    //Device developer will specify title,axis label  for chart
        title: 'Temperature',
        hAxis: {title: 'Time', titleTextStyle: {color: '#333'}}, //Added hAxis and vAxis label
        vAxis: {title: 'TempValue',  minValue: 0, titleTextStyle: {color: '#333'}},
        curveType: 'function',
        animation: {
            duration: 1000,
            easing: 'in'
        },
        legend: {position: 'bottom'}
    };
    function addDataPoint(dataPoint) { 
        if (data.getNumberOfRows() > maxDataPoints) {
            data.removeRow(0);
        }
        // Device developer will specify following value based on ref A
        data.addRow([getTime(), dataPoint.value]);
        chart.draw(data, options); 
    }
    function getTime() {
        var d = new Date();
        return d.toLocaleTimeString();
    }
    function doPoll() { 

        $.getJSON('http://localhost:8686/temperatureData',
                    function (result) {
                    addDataPoint(result); 
                    // Device developer will specify polling time 
                    setTimeout(doPoll,1000);
                });

    }
    doPoll();
});

Error from string template is shown below:

problem parsing template 'JavaSE/client'
line 21:10: expecting '$', found '<EOF>'
at     org.antlr.stringtemplate.language.DefaultTemplateLexer.nextToken(DefaultTemplateLexer.java:149)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:116)
at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
at org.antlr.stringtemplate.StringTemplateGroup.defineTemplate(StringTemplateGroup.java:679)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplate(StringTemplateGroup.java:553)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplate(StringTemplateGroup.java:629)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplateFromBeneathRootDirOrCLASSPATH(StringTemplateGroup.java:597)
at org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:480)
at org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
at org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
at iotsuite.codegenerator.JavaFrameworkFromST.generateVisualization_Client(JavaFrameworkFromST.java:180)
at iotsuite.compiler.ActuatorCompiler.generateVisualization_Client(ActuatorCompiler.java:108)
at iotsuite.compiler.ActuatorCompiler.generateActuatorCode(ActuatorCompiler.java:67)
at iotsuite.parser.VocabSpecParser.actuator_def(VocabSpecParser.java:1043)
at iotsuite.parser.VocabSpecParser.abilities_def(VocabSpecParser.java:318)
at iotsuite.parser.VocabSpecParser.vocabSpec(VocabSpecParser.java:132)
at iotsuite.parser.Main.main(Main.java:30)
abc
  • 190
  • 1
  • 4
  • 16
  • 1
    You have set the STG delimiters to `$`, so a `$` in the text of the template is confusing the ST parser -- it is not an EOF char. The ST documentation clearly identifies the backslash character as its escape character. – GRosenberg Nov 23 '15 at 02:05

1 Answers1

0

Have you tried something like

var dollarsign = '$'
alert(dollarsign);

This way you can print '$' without the script seeing it as a '$'

https://jsfiddle.net/Lcm3hp3f/

GRX
  • 479
  • 1
  • 5
  • 22